@@ -43,7 +43,7 @@ static inline JsonPathExecResult recursiveExecute(JsonPathExecContext *cxt,
4343 JsonPathItem * jsp , JsonbValue * jb ,
4444 JsonValueList * found );
4545
46- static JsonPathExecResult recursiveExecuteUnwrap (JsonPathExecContext * cxt ,
46+ static inline JsonPathExecResult recursiveExecuteUnwrap (JsonPathExecContext * cxt ,
4747 JsonPathItem * jsp , JsonbValue * jb , JsonValueList * found );
4848
4949static inline JsonbValue * wrapItemsInArray (const JsonValueList * items );
@@ -1958,51 +1958,56 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
19581958}
19591959
19601960static JsonPathExecResult
1961- recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
1962- JsonbValue * jb , JsonValueList * found )
1961+ recursiveExecuteUnwrapArray (JsonPathExecContext * cxt , JsonPathItem * jsp ,
1962+ JsonbValue * jb , JsonValueList * found )
19631963{
1964- if (cxt -> lax && JsonbType (jb ) == jbvArray )
1964+ JsonPathExecResult res = jperNotFound ;
1965+
1966+ if (jb -> type == jbvArray )
19651967 {
1966- JsonPathExecResult res = jperNotFound ;
1968+ JsonbValue * elem = jb -> val .array .elems ;
1969+ JsonbValue * last = elem + jb -> val .array .nElems ;
19671970
1968- if ( jb -> type == jbvArray )
1971+ for (; elem < last ; elem ++ )
19691972 {
1970- JsonbValue * elem = jb -> val .array .elems ;
1971- JsonbValue * last = elem + jb -> val .array .nElems ;
1973+ res = recursiveExecuteNoUnwrap (cxt , jsp , elem , found );
19721974
1973- for (; elem < last ; elem ++ )
1974- {
1975- res = recursiveExecuteNoUnwrap (cxt , jsp , elem , found );
1975+ if (jperIsError (res ))
1976+ break ;
1977+ if (res == jperOk && !found )
1978+ break ;
1979+ }
1980+ }
1981+ else
1982+ {
1983+ JsonbValue v ;
1984+ JsonbIterator * it ;
1985+ JsonbIteratorToken tok ;
1986+
1987+ it = JsonbIteratorInit (jb -> val .binary .data );
19761988
1989+ while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
1990+ {
1991+ if (tok == WJB_ELEM )
1992+ {
1993+ res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
19771994 if (jperIsError (res ))
19781995 break ;
19791996 if (res == jperOk && !found )
19801997 break ;
19811998 }
19821999 }
1983- else
1984- {
1985- JsonbValue v ;
1986- JsonbIterator * it ;
1987- JsonbIteratorToken tok ;
1988-
1989- it = JsonbIteratorInit (jb -> val .binary .data );
2000+ }
19902001
1991- while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
1992- {
1993- if (tok == WJB_ELEM )
1994- {
1995- res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
1996- if (jperIsError (res ))
1997- break ;
1998- if (res == jperOk && !found )
1999- break ;
2000- }
2001- }
2002- }
2002+ return res ;
2003+ }
20032004
2004- return res ;
2005- }
2005+ static inline JsonPathExecResult
2006+ recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2007+ JsonbValue * jb , JsonValueList * found )
2008+ {
2009+ if (cxt -> lax && JsonbType (jb ) == jbvArray )
2010+ return recursiveExecuteUnwrapArray (cxt , jsp , jb , found );
20062011
20072012 return recursiveExecuteNoUnwrap (cxt , jsp , jb , found );
20082013}
0 commit comments