Skip to content

Commit 7302514

Browse files
committed
Add const qualifiers to internal range type APIs
Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/flat/dc9b45fa-b950-fadc-4751-85d6f729df55%402ndquadrant.com
1 parent f921ea6 commit 7302514

File tree

5 files changed

+86
-86
lines changed

5 files changed

+86
-86
lines changed

src/backend/utils/adt/rangetypes.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ elem_contained_by_range(PG_FUNCTION_ARGS)
554554

555555
/* equality (internal version) */
556556
bool
557-
range_eq_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
557+
range_eq_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
558558
{
559559
RangeBound lower1,
560560
lower2;
@@ -599,7 +599,7 @@ range_eq(PG_FUNCTION_ARGS)
599599

600600
/* inequality (internal version) */
601601
bool
602-
range_ne_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
602+
range_ne_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
603603
{
604604
return (!range_eq_internal(typcache, r1, r2));
605605
}
@@ -645,7 +645,7 @@ range_contained_by(PG_FUNCTION_ARGS)
645645

646646
/* strictly left of? (internal version) */
647647
bool
648-
range_before_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
648+
range_before_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
649649
{
650650
RangeBound lower1,
651651
lower2;
@@ -683,7 +683,7 @@ range_before(PG_FUNCTION_ARGS)
683683

684684
/* strictly right of? (internal version) */
685685
bool
686-
range_after_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
686+
range_after_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
687687
{
688688
RangeBound lower1,
689689
lower2;
@@ -779,7 +779,7 @@ bounds_adjacent(TypeCacheEntry *typcache, RangeBound boundA, RangeBound boundB)
779779

780780
/* adjacent to (but not overlapping)? (internal version) */
781781
bool
782-
range_adjacent_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
782+
range_adjacent_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
783783
{
784784
RangeBound lower1,
785785
lower2;
@@ -822,7 +822,7 @@ range_adjacent(PG_FUNCTION_ARGS)
822822

823823
/* overlaps? (internal version) */
824824
bool
825-
range_overlaps_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
825+
range_overlaps_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
826826
{
827827
RangeBound lower1,
828828
lower2;
@@ -868,7 +868,7 @@ range_overlaps(PG_FUNCTION_ARGS)
868868

869869
/* does not extend to right of? (internal version) */
870870
bool
871-
range_overleft_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
871+
range_overleft_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
872872
{
873873
RangeBound lower1,
874874
lower2;
@@ -909,7 +909,7 @@ range_overleft(PG_FUNCTION_ARGS)
909909

910910
/* does not extend to left of? (internal version) */
911911
bool
912-
range_overright_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
912+
range_overright_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
913913
{
914914
RangeBound lower1,
915915
lower2;
@@ -1696,7 +1696,7 @@ range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper,
16961696
* RangeBound structs will be pointers into the given range object.
16971697
*/
16981698
void
1699-
range_deserialize(TypeCacheEntry *typcache, RangeType *range,
1699+
range_deserialize(TypeCacheEntry *typcache, const RangeType *range,
17001700
RangeBound *lower, RangeBound *upper, bool *empty)
17011701
{
17021702
char flags;
@@ -1711,7 +1711,7 @@ range_deserialize(TypeCacheEntry *typcache, RangeType *range,
17111711
Assert(RangeTypeGetOid(range) == typcache->type_id);
17121712

17131713
/* fetch the flag byte from datum's last byte */
1714-
flags = *((char *) range + VARSIZE(range) - 1);
1714+
flags = *((const char *) range + VARSIZE(range) - 1);
17151715

17161716
/* fetch information about range's element type */
17171717
typlen = typcache->rngelemtype->typlen;
@@ -1763,7 +1763,7 @@ range_deserialize(TypeCacheEntry *typcache, RangeType *range,
17631763
* the full results of range_deserialize.
17641764
*/
17651765
char
1766-
range_get_flags(RangeType *range)
1766+
range_get_flags(const RangeType *range)
17671767
{
17681768
/* fetch the flag byte from datum's last byte */
17691769
return *((char *) range + VARSIZE(range) - 1);
@@ -1832,7 +1832,7 @@ make_range(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper,
18321832
* but one is an upper bound and the other a lower bound.
18331833
*/
18341834
int
1835-
range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
1835+
range_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
18361836
{
18371837
int32 result;
18381838

@@ -1906,8 +1906,8 @@ range_cmp_bounds(TypeCacheEntry *typcache, RangeBound *b1, RangeBound *b2)
19061906
* infinity is plus or minus.
19071907
*/
19081908
int
1909-
range_cmp_bound_values(TypeCacheEntry *typcache, RangeBound *b1,
1910-
RangeBound *b2)
1909+
range_cmp_bound_values(TypeCacheEntry *typcache, const RangeBound *b1,
1910+
const RangeBound *b2)
19111911
{
19121912
/*
19131913
* First, handle cases involving infinity, which don't require invoking
@@ -2300,7 +2300,7 @@ range_bound_escape(const char *value)
23002300
* the necessary typcache entry.
23012301
*/
23022302
bool
2303-
range_contains_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
2303+
range_contains_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
23042304
{
23052305
RangeBound lower1;
23062306
RangeBound upper1;
@@ -2332,7 +2332,7 @@ range_contains_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
23322332
}
23332333

23342334
bool
2335-
range_contained_by_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
2335+
range_contained_by_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
23362336
{
23372337
return range_contains_internal(typcache, r2, r1);
23382338
}
@@ -2341,7 +2341,7 @@ range_contained_by_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *
23412341
* Test whether range r contains a specific element value.
23422342
*/
23432343
bool
2344-
range_contains_elem_internal(TypeCacheEntry *typcache, RangeType *r, Datum val)
2344+
range_contains_elem_internal(TypeCacheEntry *typcache, const RangeType *r, Datum val)
23452345
{
23462346
RangeBound lower;
23472347
RangeBound upper;

src/backend/utils/adt/rangetypes_gist.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ typedef struct
137137
static RangeType *range_super_union(TypeCacheEntry *typcache, RangeType *r1,
138138
RangeType *r2);
139139
static bool range_gist_consistent_int(TypeCacheEntry *typcache,
140-
StrategyNumber strategy, RangeType *key,
140+
StrategyNumber strategy, const RangeType *key,
141141
Datum query);
142142
static bool range_gist_consistent_leaf(TypeCacheEntry *typcache,
143-
StrategyNumber strategy, RangeType *key,
143+
StrategyNumber strategy, const RangeType *key,
144144
Datum query);
145145
static void range_gist_fallback_split(TypeCacheEntry *typcache,
146146
GistEntryVector *entryvec,
@@ -764,7 +764,7 @@ range_super_union(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
764764
*/
765765
static bool
766766
range_gist_consistent_int(TypeCacheEntry *typcache, StrategyNumber strategy,
767-
RangeType *key, Datum query)
767+
const RangeType *key, Datum query)
768768
{
769769
switch (strategy)
770770
{
@@ -836,7 +836,7 @@ range_gist_consistent_int(TypeCacheEntry *typcache, StrategyNumber strategy,
836836
*/
837837
static bool
838838
range_gist_consistent_leaf(TypeCacheEntry *typcache, StrategyNumber strategy,
839-
RangeType *key, Datum query)
839+
const RangeType *key, Datum query)
840840
{
841841
switch (strategy)
842842
{

src/backend/utils/adt/rangetypes_selfuncs.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,33 @@
3131
#include "utils/typcache.h"
3232

3333
static double calc_rangesel(TypeCacheEntry *typcache, VariableStatData *vardata,
34-
RangeType *constval, Oid operator);
34+
const RangeType *constval, Oid operator);
3535
static double default_range_selectivity(Oid operator);
3636
static double calc_hist_selectivity(TypeCacheEntry *typcache,
37-
VariableStatData *vardata, RangeType *constval,
37+
VariableStatData *vardata, const RangeType *constval,
3838
Oid operator);
3939
static double calc_hist_selectivity_scalar(TypeCacheEntry *typcache,
40-
RangeBound *constbound,
41-
RangeBound *hist, int hist_nvalues,
40+
const RangeBound *constbound,
41+
const RangeBound *hist, int hist_nvalues,
4242
bool equal);
43-
static int rbound_bsearch(TypeCacheEntry *typcache, RangeBound *value,
44-
RangeBound *hist, int hist_length, bool equal);
45-
static float8 get_position(TypeCacheEntry *typcache, RangeBound *value,
46-
RangeBound *hist1, RangeBound *hist2);
43+
static int rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value,
44+
const RangeBound *hist, int hist_length, bool equal);
45+
static float8 get_position(TypeCacheEntry *typcache, const RangeBound *value,
46+
const RangeBound *hist1, const RangeBound *hist2);
4747
static float8 get_len_position(double value, double hist1, double hist2);
48-
static float8 get_distance(TypeCacheEntry *typcache, RangeBound *bound1,
49-
RangeBound *bound2);
48+
static float8 get_distance(TypeCacheEntry *typcache, const RangeBound *bound1,
49+
const RangeBound *bound2);
5050
static int length_hist_bsearch(Datum *length_hist_values,
5151
int length_hist_nvalues, double value, bool equal);
5252
static double calc_length_hist_frac(Datum *length_hist_values,
5353
int length_hist_nvalues, double length1, double length2, bool equal);
5454
static double calc_hist_selectivity_contained(TypeCacheEntry *typcache,
55-
RangeBound *lower, RangeBound *upper,
56-
RangeBound *hist_lower, int hist_nvalues,
55+
const RangeBound *lower, RangeBound *upper,
56+
const RangeBound *hist_lower, int hist_nvalues,
5757
Datum *length_hist_values, int length_hist_nvalues);
5858
static double calc_hist_selectivity_contains(TypeCacheEntry *typcache,
59-
RangeBound *lower, RangeBound *upper,
60-
RangeBound *hist_lower, int hist_nvalues,
59+
const RangeBound *lower, const RangeBound *upper,
60+
const RangeBound *hist_lower, int hist_nvalues,
6161
Datum *length_hist_values, int length_hist_nvalues);
6262

6363
/*
@@ -229,7 +229,7 @@ rangesel(PG_FUNCTION_ARGS)
229229

230230
static double
231231
calc_rangesel(TypeCacheEntry *typcache, VariableStatData *vardata,
232-
RangeType *constval, Oid operator)
232+
const RangeType *constval, Oid operator)
233233
{
234234
double hist_selec;
235235
double selec;
@@ -371,7 +371,7 @@ calc_rangesel(TypeCacheEntry *typcache, VariableStatData *vardata,
371371
*/
372372
static double
373373
calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
374-
RangeType *constval, Oid operator)
374+
const RangeType *constval, Oid operator)
375375
{
376376
AttStatsSlot hslot;
377377
AttStatsSlot lslot;
@@ -586,8 +586,8 @@ calc_hist_selectivity(TypeCacheEntry *typcache, VariableStatData *vardata,
586586
* is true) a given const in a histogram of range bounds.
587587
*/
588588
static double
589-
calc_hist_selectivity_scalar(TypeCacheEntry *typcache, RangeBound *constbound,
590-
RangeBound *hist, int hist_nvalues, bool equal)
589+
calc_hist_selectivity_scalar(TypeCacheEntry *typcache, const RangeBound *constbound,
590+
const RangeBound *hist, int hist_nvalues, bool equal)
591591
{
592592
Selectivity selec;
593593
int index;
@@ -618,7 +618,7 @@ calc_hist_selectivity_scalar(TypeCacheEntry *typcache, RangeBound *constbound,
618618
* interpolation of portion of bounds which are less or equal to given bound.
619619
*/
620620
static int
621-
rbound_bsearch(TypeCacheEntry *typcache, RangeBound *value, RangeBound *hist,
621+
rbound_bsearch(TypeCacheEntry *typcache, const RangeBound *value, const RangeBound *hist,
622622
int hist_length, bool equal)
623623
{
624624
int lower = -1,
@@ -673,8 +673,8 @@ length_hist_bsearch(Datum *length_hist_values, int length_hist_nvalues,
673673
* Get relative position of value in histogram bin in [0,1] range.
674674
*/
675675
static float8
676-
get_position(TypeCacheEntry *typcache, RangeBound *value, RangeBound *hist1,
677-
RangeBound *hist2)
676+
get_position(TypeCacheEntry *typcache, const RangeBound *value, const RangeBound *hist1,
677+
const RangeBound *hist2)
678678
{
679679
bool has_subdiff = OidIsValid(typcache->rng_subdiff_finfo.fn_oid);
680680
float8 position;
@@ -795,7 +795,7 @@ get_len_position(double value, double hist1, double hist2)
795795
* Measure distance between two range bounds.
796796
*/
797797
static float8
798-
get_distance(TypeCacheEntry *typcache, RangeBound *bound1, RangeBound *bound2)
798+
get_distance(TypeCacheEntry *typcache, const RangeBound *bound1, const RangeBound *bound2)
799799
{
800800
bool has_subdiff = OidIsValid(typcache->rng_subdiff_finfo.fn_oid);
801801

@@ -999,8 +999,8 @@ calc_length_hist_frac(Datum *length_hist_values, int length_hist_nvalues,
999999
*/
10001000
static double
10011001
calc_hist_selectivity_contained(TypeCacheEntry *typcache,
1002-
RangeBound *lower, RangeBound *upper,
1003-
RangeBound *hist_lower, int hist_nvalues,
1002+
const RangeBound *lower, RangeBound *upper,
1003+
const RangeBound *hist_lower, int hist_nvalues,
10041004
Datum *length_hist_values, int length_hist_nvalues)
10051005
{
10061006
int i,
@@ -1109,8 +1109,8 @@ calc_hist_selectivity_contained(TypeCacheEntry *typcache,
11091109
*/
11101110
static double
11111111
calc_hist_selectivity_contains(TypeCacheEntry *typcache,
1112-
RangeBound *lower, RangeBound *upper,
1113-
RangeBound *hist_lower, int hist_nvalues,
1112+
const RangeBound *lower, const RangeBound *upper,
1113+
const RangeBound *hist_lower, int hist_nvalues,
11141114
Datum *length_hist_values, int length_hist_nvalues)
11151115
{
11161116
int i,

src/backend/utils/adt/rangetypes_spgist.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
#include "utils/datum.h"
4444
#include "utils/rangetypes.h"
4545

46-
static int16 getQuadrant(TypeCacheEntry *typcache, RangeType *centroid,
47-
RangeType *tst);
46+
static int16 getQuadrant(TypeCacheEntry *typcache, const RangeType *centroid,
47+
const RangeType *tst);
4848
static int bound_cmp(const void *a, const void *b, void *arg);
4949

50-
static int adjacent_inner_consistent(TypeCacheEntry *typcache,
51-
RangeBound *arg, RangeBound *centroid,
52-
RangeBound *prev);
53-
static int adjacent_cmp_bounds(TypeCacheEntry *typcache, RangeBound *arg,
54-
RangeBound *centroid);
50+
static int adjacent_inner_consistent(TypeCacheEntry *typcache,
51+
const RangeBound *arg, const RangeBound *centroid,
52+
const RangeBound *prev);
53+
static int adjacent_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *arg,
54+
const RangeBound *centroid);
5555

5656
/*
5757
* SP-GiST 'config' interface function.
@@ -92,7 +92,7 @@ spg_range_quad_config(PG_FUNCTION_ARGS)
9292
*----------
9393
*/
9494
static int16
95-
getQuadrant(TypeCacheEntry *typcache, RangeType *centroid, RangeType *tst)
95+
getQuadrant(TypeCacheEntry *typcache, const RangeType *centroid, const RangeType *tst)
9696
{
9797
RangeBound centroidLower,
9898
centroidUpper;
@@ -785,8 +785,8 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS)
785785
* For the "left" case, returns -1, and for the "right" case, returns 1.
786786
*/
787787
static int
788-
adjacent_cmp_bounds(TypeCacheEntry *typcache, RangeBound *arg,
789-
RangeBound *centroid)
788+
adjacent_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *arg,
789+
const RangeBound *centroid)
790790
{
791791
int cmp;
792792

@@ -887,8 +887,8 @@ adjacent_cmp_bounds(TypeCacheEntry *typcache, RangeBound *arg,
887887
*----------
888888
*/
889889
static int
890-
adjacent_inner_consistent(TypeCacheEntry *typcache, RangeBound *arg,
891-
RangeBound *centroid, RangeBound *prev)
890+
adjacent_inner_consistent(TypeCacheEntry *typcache, const RangeBound *arg,
891+
const RangeBound *centroid, const RangeBound *prev)
892892
{
893893
if (prev)
894894
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy