@@ -94,27 +94,21 @@ public Token nextToken() throws IOException {
9494 ++currentIndex ;
9595
9696 byte type = currentEntry .type ();
97- // Optimize for common JSON value types first
98- Token token ;
99- if (type < ESONEntry .TYPE_OBJECT ) {
100- // Primitive values (most common in JSON data)
101- // Order by frequency: strings, numbers, booleans, nulls
102- if (type == ESONEntry .STRING ) {
103- token = Token .VALUE_STRING ;
104- } else if (type >= ESONEntry .TYPE_INT && type <= ESONEntry .TYPE_DOUBLE ) {
105- token = Token .VALUE_NUMBER ;
106- } else if (type == ESONEntry .TYPE_TRUE || type == ESONEntry .TYPE_FALSE ) {
107- token = Token .VALUE_BOOLEAN ;
108- } else if (type == ESONEntry .TYPE_NULL ) {
109- token = Token .VALUE_NULL ;
110- } else {
111- token = TOKEN_LOOKUP [type ]; // Rare types
112- }
113- } else {
114- // Container types (less common)
97+ final Token token = switch (type ) {
98+ case ESONEntry .STRING -> Token .VALUE_STRING ;
99+ case ESONEntry .TYPE_INT , ESONEntry .TYPE_LONG , ESONEntry .TYPE_FLOAT , ESONEntry .TYPE_DOUBLE , ESONEntry .BIG_INTEGER ,
100+ ESONEntry .BIG_DECIMAL -> Token .VALUE_NUMBER ;
101+ case ESONEntry .TYPE_NULL -> Token .VALUE_NULL ;
102+ case ESONEntry .TYPE_TRUE , ESONEntry .TYPE_FALSE -> Token .VALUE_BOOLEAN ;
103+ case ESONEntry .TYPE_OBJECT -> Token .START_OBJECT ;
104+ case ESONEntry .TYPE_ARRAY -> Token .START_ARRAY ;
105+ case ESONEntry .BINARY -> Token .VALUE_EMBEDDED_OBJECT ;
106+ default -> throw new IllegalArgumentException ("Unknown type: " + type );
107+ };
108+ if (token == Token .START_OBJECT || token == Token .START_ARRAY ) {
115109 newContainer (type );
116- token = (type == ESONEntry .TYPE_OBJECT ) ? Token .START_OBJECT : Token .START_ARRAY ;
117110 }
111+ // token = TOKEN_LOOKUP[type];
118112
119113 if (IntStack .isObject (stackValue )) {
120114 nextToken = token ;
@@ -197,20 +191,25 @@ private Object materializeValue() {
197191
198192 @ Override
199193 public void skipChildren () throws IOException {
200- if (currentToken == Token .START_OBJECT || currentToken == Token .START_ARRAY ) {
201- int depth = 1 ;
202- while (depth > 0 ) {
203- Token token = nextToken ();
204- if (token == null ) {
205- break ;
206- }
207- if (token == Token .START_OBJECT || token == Token .START_ARRAY ) {
208- depth ++;
209- } else if (token == Token .END_OBJECT || token == Token .END_ARRAY ) {
210- depth --;
211- }
194+ if (currentToken != Token .START_OBJECT && currentToken != Token .START_ARRAY ) {
195+ return ;
196+ }
197+
198+ // Fast skip - trust the ESON structure
199+ int toSkip = currentEntry .offsetOrCount ();
200+
201+ while (toSkip -- > 0 ) {
202+ ESONEntry entry = keyArray .get (currentIndex ++);
203+
204+ // Only check containers - most entries are primitives in typical JSON
205+ if (entry .type () >= ESONEntry .TYPE_OBJECT ) {
206+ toSkip += entry .offsetOrCount ();
212207 }
213208 }
209+
210+ // Clean up parser state
211+ containerStack .popContainer (); // Also can skip the isEmpty check if we know we're in a container
212+ currentToken = (currentToken == Token .START_OBJECT ) ? Token .END_OBJECT : Token .END_ARRAY ;
214213 }
215214
216215 @ Override
0 commit comments