2323import java .nio .CharBuffer ;
2424import java .util .ArrayDeque ;
2525import java .util .Deque ;
26+ import java .util .List ;
2627
2728/**
2829 * Simplified XContentParser for flattened ESON structures.
@@ -40,7 +41,7 @@ public class ESONXContentParser extends AbstractXContentParser {
4041 private final XContentType xContentType ;
4142
4243 // Key array iteration state
43- private final ESONSource .KeyEntry [] keyArray ;
44+ private final List < ESONSource .KeyEntry > keyArray ;
4445 private int currentIndex = 0 ;
4546
4647 // Current token state
@@ -85,7 +86,7 @@ public ESONXContentParser(
8586 this .xContentType = xContentType ;
8687
8788 // Convert to array for efficient indexed access
88- this .keyArray = root .getKeyArray (). toArray ( new ESONSource . KeyEntry [ 0 ]) ;
89+ this .keyArray = root .getKeyArray ();
8990 }
9091
9192 @ Override
@@ -108,20 +109,22 @@ public Token nextToken() throws IOException {
108109 currentValue = null ;
109110 valueComputed = false ;
110111
112+ int size = keyArray .size ();
113+
111114 // First token - start root object
112115 if (currentToken == null ) {
113- if (currentIndex >= keyArray . length ) {
116+ if (currentIndex >= size ) {
114117 return null ;
115118 }
116- ESONSource .ObjectEntry rootEntry = (ESONSource .ObjectEntry ) keyArray [ currentIndex ] ;
119+ ESONSource .ObjectEntry rootEntry = (ESONSource .ObjectEntry ) keyArray . get ( currentIndex ) ;
117120 containerStack .push (new ContainerContext (ContainerContext .Type .OBJECT , rootEntry .fieldCount ));
118121 currentIndex ++;
119122 currentToken = Token .START_OBJECT ;
120123 return currentToken ;
121124 }
122125
123126 // Check if we've finished parsing
124- if (containerStack .isEmpty () && currentIndex >= keyArray . length ) {
127+ if (containerStack .isEmpty () && currentIndex >= size ) {
125128 return null ;
126129 }
127130
@@ -133,14 +136,14 @@ public Token nextToken() throws IOException {
133136 }
134137
135138 // If we've exhausted the array but still have containers, close them
136- if (currentIndex >= keyArray . length ) {
139+ if (currentIndex >= size ) {
137140 ContainerContext ctx = containerStack .pop ();
138141 currentToken = ctx .type == ContainerContext .Type .OBJECT ? Token .END_OBJECT : Token .END_ARRAY ;
139142 return currentToken ;
140143 }
141144
142145 // Process next entry
143- ESONSource .KeyEntry entry = keyArray [ currentIndex ] ;
146+ ESONSource .KeyEntry entry = keyArray . get ( currentIndex ) ;
144147 ContainerContext currentContainer = containerStack .peek ();
145148
146149 if (currentContainer == null ) {
0 commit comments