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

Commit ec108e7

Browse files
author
Nikita Glukhov
committed
Hide JsonbParseState struct definition
1 parent c605bb4 commit ec108e7

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/backend/utils/adt/jsonb.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ jsonb_in_object_start(void *pstate)
285285
JsonbInState *_state = (JsonbInState *) pstate;
286286

287287
_state->res = pushJsonbValue(&_state->parseState, WJB_BEGIN_OBJECT, NULL);
288-
_state->parseState->unique_keys = _state->unique_keys;
288+
JsonbParseStateSetUniqueKeys(_state->parseState, _state->unique_keys);
289289
}
290290

291291
static void
@@ -1143,8 +1143,9 @@ jsonb_build_object_worker(int nargs, Datum *args, bool *nulls, Oid *types,
11431143
memset(&result, 0, sizeof(JsonbInState));
11441144

11451145
result.res = pushJsonbValue(&result.parseState, WJB_BEGIN_OBJECT, NULL);
1146-
result.parseState->unique_keys = unique_keys;
1147-
result.parseState->skip_nulls = absent_on_null;
1146+
1147+
JsonbParseStateSetUniqueKeys(result.parseState, unique_keys);
1148+
JsonbParseStateSetSkipNulls(result.parseState, absent_on_null);
11481149

11491150
for (i = 0; i < nargs; i += 2)
11501151
{
@@ -1675,8 +1676,9 @@ jsonb_object_agg_transfn_worker(FunctionCallInfo fcinfo,
16751676
state->res = result;
16761677
result->res = pushJsonbValue(&result->parseState,
16771678
WJB_BEGIN_OBJECT, NULL);
1678-
result->parseState->unique_keys = unique_keys;
1679-
result->parseState->skip_nulls = absent_on_null;
1679+
1680+
JsonbParseStateSetUniqueKeys(result->parseState, unique_keys);
1681+
JsonbParseStateSetSkipNulls(result->parseState, absent_on_null);
16801682

16811683
MemoryContextSwitchTo(oldcontext);
16821684

src/backend/utils/adt/jsonb_util.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
#define JSONB_MAX_ELEMS (Min(MaxAllocSize / sizeof(JsonbValue), JB_CMASK))
3939
#define JSONB_MAX_PAIRS (Min(MaxAllocSize / sizeof(JsonbPair), JB_CMASK))
4040

41+
/* Conversion state used when parsing Jsonb from text, or for type coercion */
42+
struct JsonbParseState
43+
{
44+
JsonbValue contVal;
45+
Size size;
46+
struct JsonbParseState *next;
47+
bool unique_keys; /* Check object key uniqueness */
48+
bool skip_nulls; /* Skip null object fields */
49+
};
50+
4151
static void fillJsonbValue(JsonbContainer *container, int index,
4252
char *base_addr, uint32 offset,
4353
JsonbValue *result);
@@ -575,6 +585,18 @@ JsonbParseStateClone(JsonbParseState *state)
575585
return result;
576586
}
577587

588+
void
589+
JsonbParseStateSetUniqueKeys(JsonbParseState *state, bool unique_keys)
590+
{
591+
state->unique_keys = unique_keys;
592+
}
593+
594+
void
595+
JsonbParseStateSetSkipNulls(JsonbParseState *state, bool skip_nulls)
596+
{
597+
state->skip_nulls = skip_nulls;
598+
}
599+
578600
/*
579601
* Push JsonbValue into JsonbParseState.
580602
*

src/include/utils/jsonb.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,7 @@ struct JsonbPair
324324
};
325325

326326
/* Conversion state used when parsing Jsonb from text, or for type coercion */
327-
typedef struct JsonbParseState
328-
{
329-
JsonbValue contVal;
330-
Size size;
331-
struct JsonbParseState *next;
332-
bool unique_keys; /* Check object key uniqueness */
333-
bool skip_nulls; /* Skip null object fields */
334-
} JsonbParseState;
327+
typedef struct JsonbParseState JsonbParseState;
335328

336329
/*
337330
* JsonbIterator holds details of the type for each iteration. It also stores a
@@ -408,6 +401,8 @@ extern JsonbValue *pushJsonbValue(JsonbParseState **pstate,
408401
extern JsonbValue *pushScalarJsonbValue(JsonbParseState **pstate,
409402
JsonbValue *jbval, bool isKey);
410403
extern JsonbParseState *JsonbParseStateClone(JsonbParseState *state);
404+
extern void JsonbParseStateSetUniqueKeys(JsonbParseState *state, bool unique_keys);
405+
extern void JsonbParseStateSetSkipNulls(JsonbParseState *state, bool skip_nulls);
411406
extern JsonbIterator *JsonbIteratorInit(JsonbContainer *container);
412407
extern JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val,
413408
bool skipNested);

0 commit comments

Comments
 (0)