@@ -43,10 +43,11 @@ private static final class WrappingParser extends FilterXContentParser {
4343
4444 private final ContentPath contentPath ;
4545 final Deque <XContentParser > parsers = new ArrayDeque <>();
46+ private XContentParser currentParser ;
4647
4748 WrappingParser (XContentParser in , ContentPath contentPath ) throws IOException {
4849 this .contentPath = contentPath ;
49- parsers . push ( in ) ;
50+ currentParser = in ;
5051 if (in .currentToken () == Token .FIELD_NAME ) {
5152 expandDots (in );
5253 }
@@ -55,22 +56,19 @@ private static final class WrappingParser extends FilterXContentParser {
5556 @ Override
5657 public Token nextToken () throws IOException {
5758 Token token ;
58- XContentParser delegate ;
5959 // cache object field (even when final this is a valid optimization, see https://openjdk.org/jeps/8132243)
6060 var parsers = this .parsers ;
61- delegate = parsers .peek (); // Store in local variable
62- while ((token = delegate .nextToken ()) == null ) {
63- parsers .pop ();
64- if (parsers .isEmpty ()) {
61+ while ((token = currentParser .nextToken ()) == null ) {
62+ currentParser = parsers .pollFirst ();
63+ if (currentParser == null ) {
6564 return null ;
6665 }
67- delegate = parsers .peek ();
6866 }
6967
7068 if (token != Token .FIELD_NAME ) {
7169 return token ;
7270 }
73- expandDots (delegate );
71+ expandDots (currentParser );
7472 return Token .FIELD_NAME ;
7573 }
7674
@@ -149,7 +147,8 @@ private void pushSubParser(XContentParser delegate, String[] subpaths) throws IO
149147 }
150148 subParser = new SingletonValueXContentParser (delegate );
151149 }
152- parsers .push (new DotExpandingXContentParser (subParser , subpaths , location , contentPath ));
150+ parsers .push (currentParser );
151+ currentParser = new DotExpandingXContentParser (subParser , subpaths , location , contentPath );
153152 }
154153
155154 private static void throwExpectedOpen (Token token ) {
@@ -180,7 +179,7 @@ private static void throwOnBlankOrEmptyPart(String field, String part) {
180179
181180 @ Override
182181 protected XContentParser delegate () {
183- return parsers . peek () ;
182+ return currentParser ;
184183 }
185184
186185 /*
0 commit comments