Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfda6461

Browse files
author
Nikita Glukhov
committed
Refactor jsonb.h, remove redefines
1 parente3fa4c0 commitfda6461

File tree

12 files changed

+196
-187
lines changed

12 files changed

+196
-187
lines changed

‎src/backend/utils/adt/json_generic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include"miscadmin.h"
1414
#include"utils/builtins.h"
15-
#include"utils/json_generic.h"
15+
#include"utils/jsonb.h"
1616
#include"utils/memutils.h"
1717

1818
staticJson*JsonExpand(Json*tmp,Datumvalue,boolfreeValue,

‎src/backend/utils/adt/jsonb.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include"utils/datetime.h"
2626
#include"utils/json.h"
2727
#include"utils/jsonb.h"
28-
#include"utils/json_generic.h"
2928
#include"utils/jsonfuncs.h"
3029
#include"utils/lsyscache.h"
3130
#include"utils/syscache.h"

‎src/backend/utils/adt/jsonb_gin.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
#include"utils/builtins.h"
6969
#include"utils/jsonb.h"
7070
#include"utils/jsonpath.h"
71-
#include"utils/json_generic.h"
7271
#include"utils/varlena.h"
7372

7473
typedefstructPathHashStack

‎src/backend/utils/adt/jsonb_op.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include"miscadmin.h"
1818
#include"utils/builtins.h"
1919
#include"utils/jsonb.h"
20-
#include"utils/json_generic.h"
2120

2221
Datum
2322
jsonb_exists(PG_FUNCTION_ARGS)

‎src/backend/utils/adt/jsonb_util.c‎

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
*/
1414
#include"postgres.h"
1515

16-
#defineJSONB_UTIL_C
17-
1816
#include"catalog/pg_collation.h"
1917
#include"catalog/pg_type.h"
2018
#include"common/hashfn.h"
@@ -25,21 +23,21 @@
2523
#include"utils/datetime.h"
2624
#include"utils/json.h"
2725
#include"utils/jsonb.h"
28-
#include"utils/json_generic.h"
26+
#include"utils/jsonb_internals.h"
2927
#include"utils/memutils.h"
3028
#include"utils/varlena.h"
3129

3230
/*
3331
* Maximum number of elements in an array (or key/value pairs in an object).
3432
* This is limited by two things: the size of the JEntry array must fit
3533
* in MaxAllocSize, and the number of elements (or pairs) must fit in the bits
36-
* reserved for that in theJsonbContainer.header field.
34+
* reserved for that in theJsonbContainerHeader.header field.
3735
*
3836
* (The total size of an array's or object's elements is also limited by
3937
* JENTRY_OFFLENMASK, but we're not concerned about that here.)
4038
*/
41-
#defineJSONB_MAX_ELEMS (Min(MaxAllocSize / sizeof(JsonbValue),JB_CMASK))
42-
#defineJSONB_MAX_PAIRS (Min(MaxAllocSize / sizeof(JsonbPair),JB_CMASK))
39+
#defineJSONB_MAX_ELEMS (Min(MaxAllocSize / sizeof(JsonbValue),JBC_CMASK))
40+
#defineJSONB_MAX_PAIRS (Min(MaxAllocSize / sizeof(JsonbPair),JBC_CMASK))
4341

4442
/* Conversion state used when parsing Jsonb from text, or for type coercion */
4543
structJsonbParseState
@@ -56,7 +54,7 @@ typedef struct jsonbIterator
5654
JsonIteratorji;
5755

5856
/* Container being iterated */
59-
constJsonbContainer*container;
57+
constJsonbContainerHeader*container;
6058

6159
uint32nElems;/* Number of elements in children array (will
6260
* be nPairs for objects) */
@@ -82,7 +80,7 @@ typedef struct jsonbIterator
8280
JsonbIterStatestate;
8381
}jsonbIterator;
8482

85-
staticvoidfillJsonbValue(constJsonbContainer*container,intindex,
83+
staticvoidfillJsonbValue(constJsonbContainerHeader*container,intindex,
8684
char*base_addr,uint32offset,
8785
JsonbValue*result);
8886
staticintcompareJsonbScalarValue(constJsonbValue*a,constJsonbValue*b);
@@ -107,7 +105,7 @@ static void uniqueifyJsonbObject(JsonbValue *object, bool unique_keys,
107105
staticJsonbValue*pushSingleScalarJsonbValue(JsonbParseState**pstate,
108106
constJsonbValue*jbval,
109107
boolunpackBinary);
110-
staticvoidjsonbInitContainer(JsonContainerData*jc,JsonbContainer*jbc,intlen);
108+
staticvoidjsonbInitContainer(JsonContainerData*jc,JsonbContainerHeader*jbc,intlen);
111109

112110
JsonValue*
113111
JsonValueUnpackBinary(constJsonValue*jbv)
@@ -183,7 +181,7 @@ JsonValueFlatten(const JsonValue *val, JsonValueEncoder encoder,
183181
* by index within the container's JEntry array.
184182
*/
185183
staticuint32
186-
getJsonbOffset(constJsonbContainer*jc,intindex)
184+
getJsonbOffset(constJsonbContainerHeader*jc,intindex)
187185
{
188186
uint32offset=0;
189187
inti;
@@ -208,7 +206,7 @@ getJsonbOffset(const JsonbContainer *jc, int index)
208206
* The node is identified by index within the container's JEntry array.
209207
*/
210208
staticuint32
211-
getJsonbLength(constJsonbContainer*jc,intindex)
209+
getJsonbLength(constJsonbContainerHeader*jc,intindex)
212210
{
213211
uint32off;
214212
uint32len;
@@ -379,19 +377,19 @@ compareJsonbContainers(JsonContainer *a, JsonContainer *b)
379377

380378
typedefstructJsonbArrayIterator
381379
{
382-
constJsonbContainer*container;
380+
constJsonbContainerHeader*container;
383381
char*base_addr;
384382
intindex;
385383
intcount;
386384
uint32offset;
387385
}JsonbArrayIterator;
388386

389387
staticvoid
390-
JsonbArrayIteratorInit(JsonbArrayIterator*it,constJsonbContainer*container)
388+
JsonbArrayIteratorInit(JsonbArrayIterator*it,constJsonbContainerHeader*container)
391389
{
392390
it->container=container;
393391
it->index=0;
394-
it->count= (container->header&JB_CMASK);
392+
it->count= (container->header&JBC_CMASK);
395393
it->offset=0;
396394
it->base_addr= (char*) (container->children+it->count);
397395
}
@@ -431,7 +429,7 @@ JsonbArrayIteratorGetIth(JsonbArrayIterator *it, uint32 i)
431429
staticJsonbValue*
432430
jsonbFindValueInArray(JsonContainer*jsc,constJsonbValue*key)
433431
{
434-
constJsonbContainer*container=jsc->data;
432+
constJsonbContainerHeader*container=jsc->data;
435433
JsonbArrayIteratorit;
436434
JsonbValue*result=palloc(sizeof(JsonbValue));
437435

@@ -510,7 +508,7 @@ static JsonbValue *
510508
jsonbFindKeyInObject(JsonContainer*jsc,constchar*keyVal,intkeyLen,
511509
JsonValue*res)
512510
{
513-
constJsonbContainer*container=jsc->data;
511+
constJsonbContainerHeader*container=jsc->data;
514512
constJEntry*children=container->children;
515513
intcount=JsonContainerSize(jsc);
516514
char*baseAddr;
@@ -603,7 +601,7 @@ jsonbGetArrayElement(JsonContainer *jsc, uint32 i)
603601
* expanded.
604602
*/
605603
staticvoid
606-
fillJsonbValue(constJsonbContainer*container,intindex,
604+
fillJsonbValue(constJsonbContainerHeader*container,intindex,
607605
char*base_addr,uint32offset,
608606
JsonbValue*result)
609607
{
@@ -642,7 +640,7 @@ fillJsonbValue(const JsonbContainer *container, int index,
642640
result->val.binary.data=JsonContainerAlloc();
643641
jsonbInitContainer((JsonContainerData*)result->val.binary.data,
644642
/* Remove alignment padding from data pointer and length */
645-
(JsonbContainer*)(base_addr+INTALIGN(offset)),
643+
(JsonbContainerHeader*)(base_addr+INTALIGN(offset)),
646644
getJsonbLength(container,index)-
647645
(INTALIGN(offset)-offset));
648646
}
@@ -1193,40 +1191,40 @@ iteratorFromContainer(JsonContainer *container, jsonbIterator *parent)
11931191
}
11941192

11951193
/*
1196-
* Given aJsonbContainer, expand to jsonbIterator to iterate over items
1194+
* Given aJsonContainer, expand to jsonbIterator to iterate over items
11971195
* fully expanded to in-memory representation for manipulation.
11981196
*
11991197
* See jsonbIteratorNext() for notes on memory management.
12001198
*/
12011199
staticJsonIterator*
12021200
jsonbIteratorInit(JsonContainer*cont)
12031201
{
1204-
constJsonbContainer*container=cont->data;
1202+
constJsonbContainerHeader*container=cont->data;
12051203
jsonbIterator*it;
12061204

12071205
it=palloc0(sizeof(jsonbIterator));
12081206
it->ji.container=cont;
12091207
it->ji.parent=NULL;
12101208
it->ji.next=jsonbIteratorNext;
12111209
it->container=container;
1212-
it->nElems=container->header&JB_CMASK;
1210+
it->nElems=container->header&JBC_CMASK;
12131211

12141212
/* Array starts just after header */
12151213
it->children=container->children;
12161214

1217-
switch (container->header& (JB_FARRAY |JB_FOBJECT))
1215+
switch (container->header& (JBC_FARRAY |JBC_FOBJECT))
12181216
{
1219-
caseJB_FARRAY:
1217+
caseJBC_FARRAY:
12201218
it->dataProper=
12211219
(char*)it->children+it->nElems*sizeof(JEntry);
1222-
it->isScalar= (container->header&JB_FSCALAR)!=0;
1220+
it->isScalar= (container->header&JBC_FSCALAR)!=0;
12231221
/* This is either a "raw scalar", or an array */
12241222
Assert(!it->isScalar||it->nElems==1);
12251223

12261224
it->state=JBI_ARRAY_START;
12271225
break;
12281226

1229-
caseJB_FOBJECT:
1227+
caseJBC_FOBJECT:
12301228
it->dataProper=
12311229
(char*)it->children+it->nElems*sizeof(JEntry)*2;
12321230
it->state=JBI_OBJECT_START;
@@ -1816,12 +1814,12 @@ convertJsonbArray(StringInfo buffer, JEntry *pheader, const JsonbValue *val, int
18161814
* Construct the header Jentry and store it in the beginning of the
18171815
* variable-length payload.
18181816
*/
1819-
header=nElems |JB_FARRAY;
1817+
header=nElems |JBC_FARRAY;
18201818
if (val->val.array.rawScalar)
18211819
{
18221820
Assert(nElems==1);
18231821
Assert(level==0);
1824-
header |=JB_FSCALAR;
1822+
header |=JBC_FSCALAR;
18251823
}
18261824

18271825
appendToBuffer(buffer, (char*)&header,sizeof(uint32));
@@ -1902,7 +1900,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, in
19021900
* Construct the header Jentry and store it in the beginning of the
19031901
* variable-length payload.
19041902
*/
1905-
header=nPairs |JB_FOBJECT;
1903+
header=nPairs |JBC_FOBJECT;
19061904
appendToBuffer(buffer, (char*)&header,sizeof(uint32));
19071905

19081906
/* Reserve space for the JEntries of the keys and values. */
@@ -2205,21 +2203,21 @@ uniqueifyJsonbObject(JsonbValue *object, bool unique_keys, bool skip_nulls)
22052203

22062204

22072205
staticvoid
2208-
jsonbInitContainer(JsonContainerData*jc,JsonbContainer*jbc,intlen)
2206+
jsonbInitContainer(JsonContainerData*jc,JsonbContainerHeader*jbc,intlen)
22092207
{
22102208
jc->ops=&jsonbContainerOps;
22112209
jc->data=jbc;
22122210
jc->len=len;
2213-
jc->size=jbc->header&JB_CMASK;
2214-
jc->type=jbc->header&JB_FOBJECT ?jbvObject :
2215-
jbc->header&JB_FSCALAR ?jbvArray |jbvScalar :
2216-
jbvArray;
2211+
jc->size=jbc->header&JBC_CMASK;
2212+
jc->type=jbc->header&JBC_FOBJECT ?jbvObject :
2213+
jbc->header&JBC_FSCALAR ?jbvArray |jbvScalar :
2214+
jbvArray;
22172215
}
22182216

22192217
staticvoid
22202218
jsonbInit(JsonContainerData*jc,Datumvalue)
22212219
{
2222-
Jsonb*jb= (Jsonb*)DatumGetPointer(value);
2220+
JsonbDatum*jb= (JsonbDatum*)DatumGetPointer(value);
22232221
jsonbInitContainer(jc,&jb->root,VARSIZE_ANY_EXHDR(jb));
22242222
}
22252223

‎src/backend/utils/adt/jsonbsubs.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include"parser/parse_coerce.h"
2222
#include"parser/parse_expr.h"
2323
#include"utils/jsonb.h"
24-
#include"utils/json_generic.h"
2524
#include"utils/jsonfuncs.h"
2625
#include"utils/builtins.h"
2726
#include"utils/lsyscache.h"

‎src/backend/utils/adt/jsonfuncs.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include"utils/hsearch.h"
3232
#include"utils/json.h"
3333
#include"utils/jsonb.h"
34-
#include"utils/json_generic.h"
3534
#include"utils/jsonfuncs.h"
3635
#include"utils/lsyscache.h"
3736
#include"utils/memutils.h"
@@ -3171,7 +3170,6 @@ json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod,
31713170
/* fill binary jsonb value pointing to jb */
31723171
jbv.type=jbvBinary;
31733172
jbv.val.binary.data=&jsonb->root;
3174-
jbv.val.binary.len=VARSIZE(jsonb)-VARHDRSZ;
31753173
}
31763174

31773175
if (!*cache)

‎src/include/utils/json_generic.h‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#ifndefUTILS_JSON_GENERIC_H
1414
#defineUTILS_JSON_GENERIC_H
1515

16-
#defineJSON_GENERIC
17-
1816
#include"postgres.h"
1917
#include"lib/stringinfo.h"
2018
#include"utils/jsonb.h"
@@ -79,6 +77,10 @@ typedef struct Json
7977
boolis_json;/* json or jsonb */
8078
}Json;
8179

80+
typedefJsonJsonb;
81+
typedefJsonContainerJsonbContainer;
82+
83+
8284
#defineJsonIsTemporary(json)((json)->obj.isTemporary)
8385

8486
#defineJsonFlattenToJsonbDatum(json) \
@@ -117,11 +119,6 @@ typedef struct Json
117119

118120
#defineJsonbValueToJsonb JsonValueToJson
119121

120-
#ifndefJSONB_UTIL_C
121-
#defineJsonb Json
122-
#defineJsonbContainer JsonContainer
123-
#endif
124-
125122
#defineJB_ROOT_COUNT(json)JsonContainerSize(JsonRoot(json))
126123
#defineJB_ROOT_IS_SCALAR(json)JsonContainerIsScalar(JsonRoot(json))
127124
#defineJB_ROOT_IS_OBJECT(json)JsonContainerIsObject(JsonRoot(json))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp