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

Commit4178d8b

Browse files
committed
Beautify initialization of JsonValueList and JsonLikeRegexContext
Instead of tricky assignment to {0} introduce special macros, whichexplicitly initialize every field.
1 parentaa1b7f3 commit4178d8b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ typedef struct JsonLikeRegexContext
126126
intcflags;
127127
}JsonLikeRegexContext;
128128

129+
#defineEmptyJsonLikeRegexContext{NULL, 0}
130+
129131
/* Result of jsonpath predicate evaluation */
130132
typedefenumJsonPathBool
131133
{
@@ -153,6 +155,8 @@ typedef struct JsonValueList
153155
List*list;
154156
}JsonValueList;
155157

158+
#defineEmptyJsonValueList{NULL, NIL}
159+
156160
typedefstructJsonValueListIterator
157161
{
158162
JsonbValue*value;
@@ -321,7 +325,7 @@ jsonb_path_match(PG_FUNCTION_ARGS)
321325
Jsonb*jb=PG_GETARG_JSONB_P(0);
322326
JsonPath*jp=PG_GETARG_JSONPATH_P(1);
323327
JsonbValue*jbv;
324-
JsonValueListfound={0};
328+
JsonValueListfound=EmptyJsonValueList;
325329
Jsonb*vars=NULL;
326330
boolsilent= true;
327331

@@ -379,7 +383,7 @@ jsonb_path_query(PG_FUNCTION_ARGS)
379383
MemoryContextoldcontext;
380384
Jsonb*vars;
381385
boolsilent;
382-
JsonValueListfound={0};
386+
JsonValueListfound=EmptyJsonValueList;
383387

384388
funcctx=SRF_FIRSTCALL_INIT();
385389
oldcontext=MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -420,7 +424,7 @@ jsonb_path_query_array(FunctionCallInfo fcinfo)
420424
{
421425
Jsonb*jb=PG_GETARG_JSONB_P(0);
422426
JsonPath*jp=PG_GETARG_JSONPATH_P(1);
423-
JsonValueListfound={0};
427+
JsonValueListfound=EmptyJsonValueList;
424428
Jsonb*vars=PG_GETARG_JSONB_P(2);
425429
boolsilent=PG_GETARG_BOOL(3);
426430

@@ -439,7 +443,7 @@ jsonb_path_query_first(FunctionCallInfo fcinfo)
439443
{
440444
Jsonb*jb=PG_GETARG_JSONB_P(0);
441445
JsonPath*jp=PG_GETARG_JSONPATH_P(1);
442-
JsonValueListfound={0};
446+
JsonValueListfound=EmptyJsonValueList;
443447
Jsonb*vars=PG_GETARG_JSONB_P(2);
444448
boolsilent=PG_GETARG_BOOL(3);
445449

@@ -510,7 +514,7 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors,
510514
* In strict mode we must get a complete list of values to check that
511515
* there are no errors at all.
512516
*/
513-
JsonValueListvals={0};
517+
JsonValueListvals=EmptyJsonValueList;
514518

515519
res=executeItem(&cxt,&jsp,&jbv,&vals);
516520

@@ -1134,7 +1138,7 @@ executeItemOptUnwrapResult(JsonPathExecContext *cxt, JsonPathItem *jsp,
11341138
{
11351139
if (unwrap&&jspAutoUnwrap(cxt))
11361140
{
1137-
JsonValueListseq={0};
1141+
JsonValueListseq=EmptyJsonValueList;
11381142
JsonValueListIteratorit;
11391143
JsonPathExecResultres=executeItem(cxt,jsp,jb,&seq);
11401144
JsonbValue*item;
@@ -1262,7 +1266,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
12621266
* regexes, but we use Postgres regexes here. 'flags' is a
12631267
* string literal converted to integer flags at compile-time.
12641268
*/
1265-
JsonLikeRegexContextlrcxt={0};
1269+
JsonLikeRegexContextlrcxt=EmptyJsonLikeRegexContext;
12661270

12671271
jspInitByBuffer(&larg,jsp->base,
12681272
jsp->content.like_regex.expr);
@@ -1280,7 +1284,7 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
12801284
* In strict mode we must get a complete list of values to
12811285
* check that there are no errors at all.
12821286
*/
1283-
JsonValueListvals={0};
1287+
JsonValueListvals=EmptyJsonValueList;
12841288
JsonPathExecResultres=
12851289
executeItemOptUnwrapResultNoThrow(cxt,&larg,jb,
12861290
false,&vals);
@@ -1432,8 +1436,8 @@ executePredicate(JsonPathExecContext *cxt, JsonPathItem *pred,
14321436
{
14331437
JsonPathExecResultres;
14341438
JsonValueListIteratorlseqit;
1435-
JsonValueListlseq={0};
1436-
JsonValueListrseq={0};
1439+
JsonValueListlseq=EmptyJsonValueList;
1440+
JsonValueListrseq=EmptyJsonValueList;
14371441
JsonbValue*lval;
14381442
boolerror= false;
14391443
boolfound= false;
@@ -1511,8 +1515,8 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
15111515
{
15121516
JsonPathExecResultjper;
15131517
JsonPathItemelem;
1514-
JsonValueListlseq={0};
1515-
JsonValueListrseq={0};
1518+
JsonValueListlseq=EmptyJsonValueList;
1519+
JsonValueListrseq=EmptyJsonValueList;
15161520
JsonbValue*lval;
15171521
JsonbValue*rval;
15181522
Numericres;
@@ -1586,7 +1590,7 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
15861590
JsonPathExecResultjper;
15871591
JsonPathExecResultjper2;
15881592
JsonPathItemelem;
1589-
JsonValueListseq={0};
1593+
JsonValueListseq=EmptyJsonValueList;
15901594
JsonValueListIteratorit;
15911595
JsonbValue*val;
15921596
boolhasNext;
@@ -2124,7 +2128,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
21242128
int32*index)
21252129
{
21262130
JsonbValue*jbv;
2127-
JsonValueListfound={0};
2131+
JsonValueListfound=EmptyJsonValueList;
21282132
JsonPathExecResultres=executeItem(cxt,jsp,jb,&found);
21292133
Datumnumeric_index;
21302134
boolhave_error= false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp