Skip to content

Commit f13f1fd

Browse files
author
Nikita Glukhov
committed
Optimize JsonToJsonValue() for jsonv containers
1 parent 5539983 commit f13f1fd

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/backend/utils/adt/json_generic.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,9 @@ jsonvContainerOps =
562562
JsonValue *
563563
JsonToJsonValue(Json *json, JsonValue *jv)
564564
{
565+
if (JsonRoot(json)->ops == &jsonvContainerOps)
566+
return (JsonValue *) JsonRoot(json)->data;
567+
565568
if (!jv)
566569
jv = palloc(sizeof(JsonValue));
567570

@@ -741,9 +744,8 @@ jsonFlatten(Json *json)
741744
}
742745
else
743746
{
744-
JsonValue val;
745-
JsonToJsonValue(json, &val);
746-
return JsonValueToJsonb(&val);
747+
JsonValue val;
748+
return JsonValueToJsonb(JsonToJsonValue(json, &val));
747749
}
748750
}
749751
#endif

src/backend/utils/adt/jsonb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,11 @@ datum_to_jsonb(Datum val, bool is_null, JsonbInState *result,
911911
{
912912
JsonbIteratorToken type;
913913

914-
JsonToJsonValue(jsonb, &jb);
915914

916915
if (result->parseState)
917916
{
918-
pushScalarJsonbValue(&result->parseState, &jb,
917+
pushScalarJsonbValue(&result->parseState,
918+
JsonToJsonValue(jsonb, &jb),
919919
false, false);
920920
return;
921921
}

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