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

Commit dd70c15

Browse files
author
Nikita Glukhov
committed
Extract recursiveExecuteUnwrapArray()
1 parent 1a1df16 commit dd70c15

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

src/backend/utils/adt/jsonpath_exec.c

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline JsonPathExecResult recursiveExecute(JsonPathExecContext *cxt,
4141
JsonPathItem *jsp, JsonbValue *jb,
4242
JsonValueList *found);
4343

44-
static JsonPathExecResult recursiveExecuteUnwrap(JsonPathExecContext *cxt,
44+
static inline JsonPathExecResult recursiveExecuteUnwrap(JsonPathExecContext *cxt,
4545
JsonPathItem *jsp, JsonbValue *jb, JsonValueList *found);
4646

4747
static inline JsonbValue *wrapItemsInArray(const JsonValueList *items);
@@ -1814,51 +1814,56 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
18141814
}
18151815

18161816
static JsonPathExecResult
1817-
recursiveExecuteUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1818-
JsonbValue *jb, JsonValueList *found)
1817+
recursiveExecuteUnwrapArray(JsonPathExecContext *cxt, JsonPathItem *jsp,
1818+
JsonbValue *jb, JsonValueList *found)
18191819
{
1820-
if (cxt->lax && JsonbType(jb) == jbvArray)
1820+
JsonPathExecResult res = jperNotFound;
1821+
1822+
if (jb->type == jbvArray)
18211823
{
1822-
JsonPathExecResult res = jperNotFound;
1824+
JsonbValue *elem = jb->val.array.elems;
1825+
JsonbValue *last = elem + jb->val.array.nElems;
18231826

1824-
if (jb->type == jbvArray)
1827+
for (; elem < last; elem++)
18251828
{
1826-
JsonbValue *elem = jb->val.array.elems;
1827-
JsonbValue *last = elem + jb->val.array.nElems;
1829+
res = recursiveExecuteNoUnwrap(cxt, jsp, elem, found);
18281830

1829-
for (; elem < last; elem++)
1830-
{
1831-
res = recursiveExecuteNoUnwrap(cxt, jsp, elem, found);
1831+
if (jperIsError(res))
1832+
break;
1833+
if (res == jperOk && !found)
1834+
break;
1835+
}
1836+
}
1837+
else
1838+
{
1839+
JsonbValue v;
1840+
JsonbIterator *it;
1841+
JsonbIteratorToken tok;
1842+
1843+
it = JsonbIteratorInit(jb->val.binary.data);
18321844

1845+
while ((tok = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
1846+
{
1847+
if (tok == WJB_ELEM)
1848+
{
1849+
res = recursiveExecuteNoUnwrap(cxt, jsp, &v, found);
18331850
if (jperIsError(res))
18341851
break;
18351852
if (res == jperOk && !found)
18361853
break;
18371854
}
18381855
}
1839-
else
1840-
{
1841-
JsonbValue v;
1842-
JsonbIterator *it;
1843-
JsonbIteratorToken tok;
1844-
1845-
it = JsonbIteratorInit(jb->val.binary.data);
1856+
}
18461857

1847-
while ((tok = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
1848-
{
1849-
if (tok == WJB_ELEM)
1850-
{
1851-
res = recursiveExecuteNoUnwrap(cxt, jsp, &v, found);
1852-
if (jperIsError(res))
1853-
break;
1854-
if (res == jperOk && !found)
1855-
break;
1856-
}
1857-
}
1858-
}
1858+
return res;
1859+
}
18591860

1860-
return res;
1861-
}
1861+
static inline JsonPathExecResult
1862+
recursiveExecuteUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
1863+
JsonbValue *jb, JsonValueList *found)
1864+
{
1865+
if (cxt->lax && JsonbType(jb) == jbvArray)
1866+
return recursiveExecuteUnwrapArray(cxt, jsp, jb, found);
18621867

18631868
return recursiveExecuteNoUnwrap(cxt, jsp, jb, found);
18641869
}

0 commit comments

Comments
 (0)