Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7ace019

Browse files
author
Nikita Glukhov
committed
Add const qualifiers for JsonbValue * parameters
1 parent e30954c commit 7ace019

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ struct JsonbParseState
5151
struct JsonbIterator
5252
{
5353
/* Container being iterated */
54-
JsonbContainer *container;
54+
const JsonbContainer *container;
5555
uint32 nElems; /* Number of elements in children array (will
5656
* be nPairs for objects) */
5757
bool isScalar; /* Pseudo-array scalar value? */
58-
JEntry *children; /* JEntrys for child nodes */
58+
const JEntry *children; /* JEntrys for child nodes */
5959
/* Data proper. This points to the beginning of the variable-length data */
6060
char *dataProper;
6161

@@ -78,16 +78,16 @@ struct JsonbIterator
7878
struct JsonbIterator *parent;
7979
};
8080

81-
static void fillJsonbValue(JsonbContainer *container, int index,
81+
static void fillJsonbValue(const JsonbContainer *container, int index,
8282
char *base_addr, uint32 offset,
8383
JsonbValue *result);
84-
static bool equalsJsonbScalarValue(JsonbValue *a, JsonbValue *b);
85-
static int compareJsonbScalarValue(JsonbValue *a, JsonbValue *b);
86-
static Jsonb *convertToJsonb(JsonbValue *val);
87-
static void convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level);
88-
static void convertJsonbArray(StringInfo buffer, JEntry *header, JsonbValue *val, int level);
89-
static void convertJsonbObject(StringInfo buffer, JEntry *header, JsonbValue *val, int level);
90-
static void convertJsonbScalar(StringInfo buffer, JEntry *header, JsonbValue *scalarVal);
84+
static bool equalsJsonbScalarValue(const JsonbValue *a, const JsonbValue *b);
85+
static int compareJsonbScalarValue(const JsonbValue *a, const JsonbValue *b);
86+
static Jsonb *convertToJsonb(const JsonbValue *val);
87+
static void convertJsonbValue(StringInfo buffer, JEntry *header, const JsonbValue *val, int level);
88+
static void convertJsonbArray(StringInfo buffer, JEntry *header, const JsonbValue *val, int level);
89+
static void convertJsonbObject(StringInfo buffer, JEntry *header, const JsonbValue *val, int level);
90+
static void convertJsonbScalar(StringInfo buffer, JEntry *header, const JsonbValue *scalarVal);
9191

9292
static int reserveFromBuffer(StringInfo buffer, int len);
9393
static void appendToBuffer(StringInfo buffer, const char *data, int len);
@@ -97,9 +97,9 @@ static short padBufferToInt(StringInfo buffer);
9797
static JsonbIterator *iteratorFromContainer(JsonbContainer *container, JsonbIterator *parent);
9898
static JsonbIterator *freeAndGetParent(JsonbIterator *it);
9999
static JsonbParseState *pushState(JsonbParseState **pstate);
100-
static void appendKey(JsonbParseState *pstate, JsonbValue *scalarVal);
101-
static void appendValue(JsonbParseState *pstate, JsonbValue *scalarVal);
102-
static void appendElement(JsonbParseState *pstate, JsonbValue *scalarVal);
100+
static void appendKey(JsonbParseState *pstate, const JsonbValue *scalarVal);
101+
static void appendValue(JsonbParseState *pstate, const JsonbValue *scalarVal);
102+
static void appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal);
103103
static int lengthCompareJsonbStringValue(const void *a, const void *b);
104104
static int lengthCompareJsonbString(const char *val1, int len1,
105105
const char *val2, int len2);
@@ -108,9 +108,9 @@ static void uniqueifyJsonbObject(JsonbValue *object, bool unique_keys,
108108
bool skip_nulls);
109109
static JsonbValue *pushJsonbValueScalar(JsonbParseState **pstate,
110110
JsonbIteratorToken seq,
111-
JsonbValue *scalarVal);
111+
const JsonbValue *scalarVal);
112112
static JsonbValue *pushSingleScalarJsonbValue(JsonbParseState **pstate,
113-
JsonbValue *jbval);
113+
const JsonbValue *jbval);
114114

115115
void
116116
JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)
@@ -375,10 +375,10 @@ compareJsonbContainers(JsonbContainer *a, JsonbContainer *b)
375375
* return NULL. Otherwise, return palloc()'d copy of value.
376376
*/
377377
JsonbValue *
378-
findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
378+
findJsonbValueFromContainer(const JsonbContainer *container, uint32 flags,
379379
JsonbValue *key)
380380
{
381-
JEntry *children = container->children;
381+
const JEntry *children = container->children;
382382
int count = JsonContainerSize(container);
383383

384384
Assert((flags & ~(JB_FARRAY | JB_FOBJECT)) == 0);
@@ -429,10 +429,10 @@ findJsonbValueFromContainer(JsonbContainer *container, uint32 flags,
429429
* 'res' can be passed in as NULL, in which case it's newly palloc'ed here.
430430
*/
431431
JsonbValue *
432-
getKeyJsonValueFromContainer(JsonbContainer *container,
432+
getKeyJsonValueFromContainer(const JsonbContainer *container,
433433
const char *keyVal, int keyLen, JsonbValue *res)
434434
{
435-
JEntry *children = container->children;
435+
const JEntry *children = container->children;
436436
int count = JsonContainerSize(container);
437437
char *baseAddr;
438438
uint32 stopLow,
@@ -536,7 +536,7 @@ getIthJsonbValueFromContainer(JsonbContainer *container, uint32 i)
536536
* expanded.
537537
*/
538538
static void
539-
fillJsonbValue(JsonbContainer *container, int index,
539+
fillJsonbValue(const JsonbContainer *container, int index,
540540
char *base_addr, uint32 offset,
541541
JsonbValue *result)
542542
{
@@ -638,7 +638,7 @@ JsonbParseStateSetSkipNulls(JsonbParseState *state, bool skip_nulls)
638638
*/
639639
JsonbValue *
640640
pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
641-
JsonbValue *jbval)
641+
const JsonbValue *jbval)
642642
{
643643
JsonbIterator *it;
644644
JsonbValue *res = NULL;
@@ -712,7 +712,7 @@ pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq,
712712
*/
713713
static JsonbValue *
714714
pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
715-
JsonbValue *scalarVal)
715+
const JsonbValue *scalarVal)
716716
{
717717
JsonbValue *result = NULL;
718718

@@ -799,7 +799,7 @@ pushJsonbValueScalar(JsonbParseState **pstate, JsonbIteratorToken seq,
799799
}
800800

801801
static JsonbValue *
802-
pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
802+
pushSingleScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval)
803803
{
804804
/* single root scalar */
805805
JsonbValue va;
@@ -814,7 +814,7 @@ pushSingleScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval)
814814
}
815815

816816
static JsonbValue *
817-
pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
817+
pushNestedScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
818818
bool isKey)
819819
{
820820
switch ((*pstate)->contVal.type)
@@ -830,7 +830,8 @@ pushNestedScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval,
830830
}
831831

832832
JsonbValue *
833-
pushScalarJsonbValue(JsonbParseState **pstate, JsonbValue *jbval, bool isKey)
833+
pushScalarJsonbValue(JsonbParseState **pstate, const JsonbValue *jbval,
834+
bool isKey)
834835
{
835836
return *pstate == NULL
836837
? pushSingleScalarJsonbValue(pstate, jbval)
@@ -857,7 +858,7 @@ pushState(JsonbParseState **pstate)
857858
* pushJsonbValue() worker: Append a pair key to state when generating a Jsonb
858859
*/
859860
static void
860-
appendKey(JsonbParseState *pstate, JsonbValue *string)
861+
appendKey(JsonbParseState *pstate, const JsonbValue *string)
861862
{
862863
JsonbValue *object = &pstate->contVal;
863864

@@ -886,7 +887,7 @@ appendKey(JsonbParseState *pstate, JsonbValue *string)
886887
* Jsonb
887888
*/
888889
static void
889-
appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
890+
appendValue(JsonbParseState *pstate, const JsonbValue *scalarVal)
890891
{
891892
JsonbValue *object = &pstate->contVal;
892893

@@ -899,7 +900,7 @@ appendValue(JsonbParseState *pstate, JsonbValue *scalarVal)
899900
* pushJsonbValue() worker: Append an element to state when generating a Jsonb
900901
*/
901902
static void
902-
appendElement(JsonbParseState *pstate, JsonbValue *scalarVal)
903+
appendElement(JsonbParseState *pstate, const JsonbValue *scalarVal)
903904
{
904905
JsonbValue *array = &pstate->contVal;
905906

@@ -1512,7 +1513,7 @@ JsonbHashScalarValueExtended(const JsonbValue *scalarVal, uint64 *hash,
15121513
* Are two scalar JsonbValues of the same type a and b equal?
15131514
*/
15141515
static bool
1515-
equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1516+
equalsJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
15161517
{
15171518
if (aScalar->type == bScalar->type)
15181519
{
@@ -1544,7 +1545,7 @@ equalsJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
15441545
* operators, where a lexical sort order is generally expected.
15451546
*/
15461547
static int
1547-
compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar)
1548+
compareJsonbScalarValue(const JsonbValue *aScalar, const JsonbValue *bScalar)
15481549
{
15491550
if (aScalar->type == bScalar->type)
15501551
{
@@ -1659,7 +1660,7 @@ padBufferToInt(StringInfo buffer)
16591660
* Given a JsonbValue, convert to Jsonb. The result is palloc'd.
16601661
*/
16611662
static Jsonb *
1662-
convertToJsonb(JsonbValue *val)
1663+
convertToJsonb(const JsonbValue *val)
16631664
{
16641665
StringInfoData buffer;
16651666
JEntry jentry;
@@ -1701,7 +1702,7 @@ convertToJsonb(JsonbValue *val)
17011702
* for debugging purposes.
17021703
*/
17031704
static void
1704-
convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
1705+
convertJsonbValue(StringInfo buffer, JEntry *header, const JsonbValue *val, int level)
17051706
{
17061707
check_stack_depth();
17071708

@@ -1726,7 +1727,7 @@ convertJsonbValue(StringInfo buffer, JEntry *header, JsonbValue *val, int level)
17261727
}
17271728

17281729
static void
1729-
convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1730+
convertJsonbArray(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
17301731
{
17311732
int base_offset;
17321733
int jentry_offset;
@@ -1810,7 +1811,7 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level
18101811
}
18111812

18121813
static void
1813-
convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int level)
1814+
convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int level)
18141815
{
18151816
int base_offset;
18161817
int jentry_offset;
@@ -1926,7 +1927,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, JsonbValue *val, int leve
19261927
}
19271928

19281929
static void
1929-
convertJsonbScalar(StringInfo buffer, JEntry *jentry, JsonbValue *scalarVal)
1930+
convertJsonbScalar(StringInfo buffer, JEntry *jentry, const JsonbValue *scalarVal)
19301931
{
19311932
int numlen;
19321933
short padlen;

src/include/utils/jsonb.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,19 @@ typedef enum /* type categories for datum_to_jsonb */
360360

361361
/* Support functions */
362362
extern int compareJsonbContainers(JsonbContainer *a, JsonbContainer *b);
363-
extern JsonbValue *findJsonbValueFromContainer(JsonbContainer *sheader,
363+
extern JsonbValue *findJsonbValueFromContainer(const JsonbContainer *sheader,
364364
uint32 flags,
365365
JsonbValue *key);
366-
extern JsonbValue *getKeyJsonValueFromContainer(JsonbContainer *container,
366+
extern JsonbValue *getKeyJsonValueFromContainer(const JsonbContainer *container,
367367
const char *keyVal, int keyLen,
368368
JsonbValue *res);
369369
extern JsonbValue *getIthJsonbValueFromContainer(JsonbContainer *sheader,
370370
uint32 i);
371371
extern JsonbValue *pushJsonbValue(JsonbParseState **pstate,
372-
JsonbIteratorToken seq, JsonbValue *jbval);
372+
JsonbIteratorToken seq,
373+
const JsonbValue *jbval);
373374
extern JsonbValue *pushScalarJsonbValue(JsonbParseState **pstate,
374-
JsonbValue *jbval, bool isKey);
375+
const JsonbValue *jbval, bool isKey);
375376
extern JsonbParseState *JsonbParseStateClone(JsonbParseState *state);
376377
extern void JsonbParseStateSetUniqueKeys(JsonbParseState *state, bool unique_keys);
377378
extern void JsonbParseStateSetSkipNulls(JsonbParseState *state, bool skip_nulls);

0 commit comments

Comments
 (0)