@@ -87,21 +87,36 @@ public Token nextToken() throws IOException {
8787 } else if (currentToken != null && containerStack .isEmpty () == false ) {
8888 int stackValue = containerStack .currentStackValue ();
8989 int remainingFields = IntStack .fieldsRemaining (stackValue );
90- boolean isObject = IntStack .isObject (stackValue );
9190 if (remainingFields > 0 ) {
9291 currentEntry = keyArray .get (currentIndex );
9392 currentValue = null ;
9493 containerStack .updateRemainingFields (stackValue - 1 );
9594 ++currentIndex ;
9695
97- final Token token ;
9896 byte type = currentEntry .type ();
99- if (type >= ESONEntry .TYPE_OBJECT ) {
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)
100115 newContainer (type );
116+ token = (type == ESONEntry .TYPE_OBJECT ) ? Token .START_OBJECT : Token .START_ARRAY ;
101117 }
102- token = TOKEN_LOOKUP [type ];
103118
104- if (isObject ) {
119+ if (IntStack . isObject ( stackValue ) ) {
105120 nextToken = token ;
106121 return currentToken = Token .FIELD_NAME ;
107122 } else {
@@ -110,7 +125,7 @@ public Token nextToken() throws IOException {
110125 } else {
111126 // End of container
112127 containerStack .popContainer ();
113- return currentToken = isObject ? Token .END_OBJECT : Token .END_ARRAY ;
128+ return currentToken = IntStack . isObject ( stackValue ) ? Token .END_OBJECT : Token .END_ARRAY ;
114129 }
115130 }
116131
@@ -138,7 +153,7 @@ private void newContainer(byte type) {
138153 }
139154 }
140155
141- private static final Token [] TOKEN_LOOKUP = new Token [32 ];
156+ private static final Token [] TOKEN_LOOKUP = new Token [16 ];
142157
143158 static {
144159 TOKEN_LOOKUP [ESONEntry .TYPE_OBJECT ] = Token .START_OBJECT ;
0 commit comments