@@ -59,6 +59,18 @@ public class UTF8StreamJsonParser
59
59
*/
60
60
final protected ByteQuadsCanonicalizer _symbols ;
61
61
62
+ /**
63
+ * Marker flag to indicate that standard symbol handling is used
64
+ * (one with symbol table assisted canonicalization. May be disabled
65
+ * in which case alternate stream-line, non-canonicalizing handling
66
+ * is used: usually due to set of symbols
67
+ * (Object property names) is unbounded and will not benefit from
68
+ * canonicalization attempts.
69
+ *
70
+ * @since 2.16
71
+ */
72
+ final protected boolean _symbolsCanonical ;
73
+
62
74
/*
63
75
/**********************************************************
64
76
/* Parsing state
@@ -192,6 +204,7 @@ public UTF8StreamJsonParser(IOContext ctxt, int features, InputStream in,
192
204
_inputStream = in ;
193
205
_objectCodec = codec ;
194
206
_symbols = sym ;
207
+ _symbolsCanonical = sym .isCanonicalizing ();
195
208
_inputBuffer = inputBuffer ;
196
209
_inputPtr = start ;
197
210
_inputEnd = end ;
@@ -2112,7 +2125,7 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
2112
2125
}
2113
2126
quads [qlen ++] = _padLastQuad (currQuad , currQuadBytes );
2114
2127
}
2115
- String name = _symbols .findName (quads , qlen );
2128
+ String name = _symbolsCanonical ? _symbols .findName (quads , qlen ) : null ;
2116
2129
if (name == null ) {
2117
2130
name = addName (quads , qlen , currQuadBytes );
2118
2131
}
@@ -2192,7 +2205,7 @@ protected String _handleOddName(int ch) throws IOException
2192
2205
}
2193
2206
quads [qlen ++] = currQuad ;
2194
2207
}
2195
- String name = _symbols .findName (quads , qlen );
2208
+ String name = _symbolsCanonical ? _symbols .findName (quads , qlen ) : null ;
2196
2209
if (name == null ) {
2197
2210
name = addName (quads , qlen , currQuadBytes );
2198
2211
}
@@ -2297,7 +2310,7 @@ protected String _parseAposName() throws IOException
2297
2310
}
2298
2311
quads [qlen ++] = _padLastQuad (currQuad , currQuadBytes );
2299
2312
}
2300
- String name = _symbols .findName (quads , qlen );
2313
+ String name = _symbolsCanonical ? _symbols .findName (quads , qlen ) : null ;
2301
2314
if (name == null ) {
2302
2315
name = addName (quads , qlen , currQuadBytes );
2303
2316
}
@@ -2314,10 +2327,12 @@ private final String findName(int q1, int lastQuadBytes)
2314
2327
throws JsonParseException , StreamConstraintsException
2315
2328
{
2316
2329
q1 = _padLastQuad (q1 , lastQuadBytes );
2317
- // Usually we'll find it from the canonical symbol table already
2318
- String name = _symbols .findName (q1 );
2319
- if (name != null ) {
2320
- return name ;
2330
+ if (_symbolsCanonical ) {
2331
+ // Usually we'll find it from the canonical symbol table already
2332
+ String name = _symbols .findName (q1 );
2333
+ if (name != null ) {
2334
+ return name ;
2335
+ }
2321
2336
}
2322
2337
// If not, more work. We'll need add stuff to buffer
2323
2338
_quadBuffer [0 ] = q1 ;
@@ -2328,10 +2343,12 @@ private final String findName(int q1, int q2, int lastQuadBytes)
2328
2343
throws JsonParseException , StreamConstraintsException
2329
2344
{
2330
2345
q2 = _padLastQuad (q2 , lastQuadBytes );
2331
- // Usually we'll find it from the canonical symbol table already
2332
- String name = _symbols .findName (q1 , q2 );
2333
- if (name != null ) {
2334
- return name ;
2346
+ if (_symbolsCanonical ) {
2347
+ // Usually we'll find it from the canonical symbol table already
2348
+ String name = _symbols .findName (q1 , q2 );
2349
+ if (name != null ) {
2350
+ return name ;
2351
+ }
2335
2352
}
2336
2353
// If not, more work. We'll need add stuff to buffer
2337
2354
_quadBuffer [0 ] = q1 ;
@@ -2343,9 +2360,11 @@ private final String findName(int q1, int q2, int q3, int lastQuadBytes)
2343
2360
throws JsonParseException , StreamConstraintsException
2344
2361
{
2345
2362
q3 = _padLastQuad (q3 , lastQuadBytes );
2346
- String name = _symbols .findName (q1 , q2 , q3 );
2347
- if (name != null ) {
2348
- return name ;
2363
+ if (_symbolsCanonical ) {
2364
+ String name = _symbols .findName (q1 , q2 , q3 );
2365
+ if (name != null ) {
2366
+ return name ;
2367
+ }
2349
2368
}
2350
2369
int [] quads = _quadBuffer ;
2351
2370
quads [0 ] = q1 ;
@@ -2361,7 +2380,7 @@ private final String findName(int[] quads, int qlen, int lastQuad, int lastQuadB
2361
2380
_quadBuffer = quads = growArrayBy (quads , quads .length );
2362
2381
}
2363
2382
quads [qlen ++] = _padLastQuad (lastQuad , lastQuadBytes );
2364
- String name = _symbols .findName (quads , qlen );
2383
+ String name = _symbolsCanonical ? _symbols .findName (quads , qlen ) : null ;
2365
2384
if (name == null ) {
2366
2385
return addName (quads , qlen , lastQuadBytes );
2367
2386
}
@@ -2475,6 +2494,9 @@ private final String addName(int[] quads, int qlen, int lastQuadBytes)
2475
2494
2476
2495
// Ok. Now we have the character array, and can construct the String
2477
2496
String baseName = new String (cbuf , 0 , cix );
2497
+ if (!_symbolsCanonical ) {
2498
+ return baseName ;
2499
+ }
2478
2500
// And finally, un-align if necessary
2479
2501
if (lastQuadBytes < 4 ) {
2480
2502
quads [qlen -1 ] = lastQuad ;
0 commit comments