@@ -42,7 +42,7 @@ static inline JsonPathExecResult recursiveExecute(JsonPathExecContext *cxt,
4242 JsonPathItem * jsp , JsonbValue * jb ,
4343 JsonValueList * found );
4444
45- static JsonPathExecResult recursiveExecuteUnwrap (JsonPathExecContext * cxt ,
45+ static inline JsonPathExecResult recursiveExecuteUnwrap (JsonPathExecContext * cxt ,
4646 JsonPathItem * jsp , JsonbValue * jb , JsonValueList * found );
4747
4848static inline JsonbValue * wrapItemsInArray (const JsonValueList * items );
@@ -1985,51 +1985,56 @@ recursiveExecuteNoUnwrap(JsonPathExecContext *cxt, JsonPathItem *jsp,
19851985}
19861986
19871987static JsonPathExecResult
1988- recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
1989- JsonbValue * jb , JsonValueList * found )
1988+ recursiveExecuteUnwrapArray (JsonPathExecContext * cxt , JsonPathItem * jsp ,
1989+ JsonbValue * jb , JsonValueList * found )
19901990{
1991- if (cxt -> lax && JsonbType (jb ) == jbvArray )
1991+ JsonPathExecResult res = jperNotFound ;
1992+
1993+ if (jb -> type == jbvArray )
19921994 {
1993- JsonPathExecResult res = jperNotFound ;
1995+ JsonbValue * elem = jb -> val .array .elems ;
1996+ JsonbValue * last = elem + jb -> val .array .nElems ;
19941997
1995- if ( jb -> type == jbvArray )
1998+ for (; elem < last ; elem ++ )
19961999 {
1997- JsonbValue * elem = jb -> val .array .elems ;
1998- JsonbValue * last = elem + jb -> val .array .nElems ;
2000+ res = recursiveExecuteNoUnwrap (cxt , jsp , elem , found );
19992001
2000- for (; elem < last ; elem ++ )
2001- {
2002- res = recursiveExecuteNoUnwrap (cxt , jsp , elem , found );
2002+ if (jperIsError (res ))
2003+ break ;
2004+ if (res == jperOk && !found )
2005+ break ;
2006+ }
2007+ }
2008+ else
2009+ {
2010+ JsonbValue v ;
2011+ JsonbIterator * it ;
2012+ JsonbIteratorToken tok ;
2013+
2014+ it = JsonbIteratorInit (jb -> val .binary .data );
20032015
2016+ while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
2017+ {
2018+ if (tok == WJB_ELEM )
2019+ {
2020+ res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
20042021 if (jperIsError (res ))
20052022 break ;
20062023 if (res == jperOk && !found )
20072024 break ;
20082025 }
20092026 }
2010- else
2011- {
2012- JsonbValue v ;
2013- JsonbIterator * it ;
2014- JsonbIteratorToken tok ;
2015-
2016- it = JsonbIteratorInit (jb -> val .binary .data );
2027+ }
20172028
2018- while ((tok = JsonbIteratorNext (& it , & v , true)) != WJB_DONE )
2019- {
2020- if (tok == WJB_ELEM )
2021- {
2022- res = recursiveExecuteNoUnwrap (cxt , jsp , & v , found );
2023- if (jperIsError (res ))
2024- break ;
2025- if (res == jperOk && !found )
2026- break ;
2027- }
2028- }
2029- }
2029+ return res ;
2030+ }
20302031
2031- return res ;
2032- }
2032+ static inline JsonPathExecResult
2033+ recursiveExecuteUnwrap (JsonPathExecContext * cxt , JsonPathItem * jsp ,
2034+ JsonbValue * jb , JsonValueList * found )
2035+ {
2036+ if (cxt -> lax && JsonbType (jb ) == jbvArray )
2037+ return recursiveExecuteUnwrapArray (cxt , jsp , jb , found );
20332038
20342039 return recursiveExecuteNoUnwrap (cxt , jsp , jb , found );
20352040}
0 commit comments