Skip to content

Commit 9bcffbb

Browse files
committed
optimized char check for ']}'
1 parent 719ab03 commit 9bcffbb

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

src/main/java/com/fasterxml/jackson/core/json/ReaderBasedJsonParser.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ public final JsonToken nextToken() throws IOException
713713
_binaryValue = null;
714714

715715
// Closing scope?
716-
if (i == INT_RBRACKET || i == INT_RCURLY) {
716+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
717717
_closeScope(i);
718718
return _currToken;
719719
}
@@ -724,7 +724,7 @@ public final JsonToken nextToken() throws IOException
724724

725725
// Was that a trailing comma?
726726
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
727-
if ((i == INT_RBRACKET) || (i == INT_RCURLY)) {
727+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
728728
_closeScope(i);
729729
return _currToken;
730730
}
@@ -876,7 +876,7 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
876876
_binaryValue = null;
877877

878878
// Closing scope?
879-
if (i == INT_RBRACKET || i == INT_RCURLY) {
879+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
880880
_closeScope(i);
881881
return false;
882882
}
@@ -886,7 +886,7 @@ public boolean nextFieldName(SerializableString sstr) throws IOException
886886

887887
// Was that a trailing comma?
888888
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
889-
if ((i == INT_RBRACKET) || (i == INT_RCURLY)) {
889+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
890890
_closeScope(i);
891891
return false;
892892
}
@@ -950,14 +950,14 @@ public String nextFieldName() throws IOException
950950
return null;
951951
}
952952
_binaryValue = null;
953-
if (i == INT_RBRACKET || i == INT_RCURLY) {
953+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
954954
_closeScope(i);
955955
return null;
956956
}
957957
if (_parsingContext.expectComma()) {
958958
i = _skipComma(i);
959959
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
960-
if ((i == INT_RBRACKET) || (i == INT_RCURLY)) {
960+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
961961
_closeScope(i);
962962
return null;
963963
}

src/main/java/com/fasterxml/jackson/core/json/UTF8DataInputJsonParser.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public JsonToken nextToken() throws IOException
611611
_tokenInputRow = _currInputRow;
612612

613613
// Closing scope?
614-
if (i == INT_RBRACKET || i == INT_RCURLY) {
614+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
615615
_closeScope(i);
616616
return _currToken;
617617
}
@@ -625,7 +625,7 @@ public JsonToken nextToken() throws IOException
625625

626626
// Was that a trailing comma?
627627
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
628-
if (i == INT_RBRACKET || i == INT_RCURLY) {
628+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
629629
_closeScope(i);
630630
return _currToken;
631631
}
@@ -801,7 +801,7 @@ public String nextFieldName() throws IOException
801801
_binaryValue = null;
802802
_tokenInputRow = _currInputRow;
803803

804-
if (i == INT_RBRACKET || i == INT_RCURLY) {
804+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
805805
_closeScope(i);
806806
return null;
807807
}
@@ -815,7 +815,7 @@ public String nextFieldName() throws IOException
815815

816816
// Was that a trailing comma?
817817
if ((_features & FEAT_MASK_TRAILING_COMMA) != 0) {
818-
if (i == INT_RBRACKET || i == INT_RCURLY) {
818+
if ((i | 0x20) == INT_RCURLY) { // ~ '}]'
819819
_closeScope(i);
820820
return null;
821821
}

src/main/java/com/fasterxml/jackson/core/json/UTF8StreamJsonParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ protected final void _matchTrue() throws IOException
29532953
&& (buf[ptr++] == 'u')
29542954
&& (buf[ptr++] == 'e')) {
29552955
int ch = buf[ptr] & 0xFF;
2956-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
2956+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
29572957
_inputPtr = ptr;
29582958
return;
29592959
}
@@ -2972,7 +2972,7 @@ protected final void _matchFalse() throws IOException
29722972
&& (buf[ptr++] == 's')
29732973
&& (buf[ptr++] == 'e')) {
29742974
int ch = buf[ptr] & 0xFF;
2975-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
2975+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
29762976
_inputPtr = ptr;
29772977
return;
29782978
}
@@ -2990,7 +2990,7 @@ protected final void _matchNull() throws IOException
29902990
&& (buf[ptr++] == 'l')
29912991
&& (buf[ptr++] == 'l')) {
29922992
int ch = buf[ptr] & 0xFF;
2993-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
2993+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
29942994
_inputPtr = ptr;
29952995
return;
29962996
}

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingUtf8JsonParserBase.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ protected JsonToken _startFalseToken() throws IOException
11141114
&& (getByteFromBuffer(ptr++) == 's')
11151115
&& (getByteFromBuffer(ptr++) == 'e')) {
11161116
int ch = getByteFromBuffer(ptr) & 0xFF;
1117-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
1117+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
11181118
_inputPtr = ptr;
11191119
return _valueComplete(JsonToken.VALUE_FALSE);
11201120
}
@@ -1132,7 +1132,7 @@ protected JsonToken _startTrueToken() throws IOException
11321132
&& (getByteFromBuffer(ptr++) == 'u')
11331133
&& (getByteFromBuffer(ptr++) == 'e')) {
11341134
int ch = getByteFromBuffer(ptr) & 0xFF;
1135-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
1135+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
11361136
_inputPtr = ptr;
11371137
return _valueComplete(JsonToken.VALUE_TRUE);
11381138
}
@@ -1150,7 +1150,7 @@ protected JsonToken _startNullToken() throws IOException
11501150
&& (getByteFromBuffer(ptr++) == 'l')
11511151
&& (getByteFromBuffer(ptr++) == 'l')) {
11521152
int ch = getByteFromBuffer(ptr) & 0xFF;
1153-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
1153+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
11541154
_inputPtr = ptr;
11551155
return _valueComplete(JsonToken.VALUE_NULL);
11561156
}
@@ -1172,7 +1172,7 @@ protected JsonToken _finishKeywordToken(String expToken, int matched,
11721172
}
11731173
int ch = getByteFromBuffer(_inputPtr);
11741174
if (matched == end) { // need to verify trailing separator
1175-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
1175+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
11761176
return _valueComplete(result);
11771177
}
11781178
break;
@@ -1212,7 +1212,7 @@ protected JsonToken _finishNonStdToken(int type, int matched) throws IOException
12121212
}
12131213
int ch = getByteFromBuffer(_inputPtr);
12141214
if (matched == end) { // need to verify trailing separator
1215-
if (ch < INT_0 || (ch == INT_RBRACKET) || (ch == INT_RCURLY)) { // expected/allowed chars
1215+
if (ch < INT_0 || (ch | 0x20) == INT_RCURLY) { // < '0' || ~ '}]' expected/allowed chars
12161216
return _valueNonStdNumberComplete(type);
12171217
}
12181218
break;
@@ -1515,7 +1515,7 @@ protected JsonToken _startNumberLeadingZero() throws IOException
15151515
// Ok; unfortunately we have closing bracket/curly that are valid so need
15161516
// (colon not possible since this is within value, not after key)
15171517
//
1518-
if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) {
1518+
if ((ch | 0x20) != INT_RCURLY) { // ~ '}]'
15191519
--_inputPtr; // for correct error reporting
15201520
_reportUnexpectedNumberChar(ch,
15211521
"expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'");
@@ -1617,7 +1617,7 @@ protected JsonToken _finishNumberLeadingZeroes() throws IOException
16171617
// Ok; unfortunately we have closing bracket/curly that are valid so need
16181618
// (colon not possible since this is within value, not after key)
16191619
//
1620-
if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) {
1620+
if ((ch | 0x20) != INT_RCURLY) { // ~ '}]'
16211621
--_inputPtr; // for correct error reporting
16221622
_reportUnexpectedNumberChar(ch,
16231623
"expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'");
@@ -1678,7 +1678,7 @@ protected JsonToken _finishNumberLeadingPosNegZeroes(final boolean negative) thr
16781678
// Ok; unfortunately we have closing bracket/curly that are valid so need
16791679
// (colon not possible since this is within value, not after key)
16801680
//
1681-
if ((ch != INT_RBRACKET) && (ch != INT_RCURLY)) {
1681+
if ((ch | 0x20) != INT_RCURLY) { // ~ '}]'
16821682
--_inputPtr; // for correct error reporting
16831683
_reportUnexpectedNumberChar(ch,
16841684
"expected digit (0-9), decimal point (.) or exponent indicator (e/E) to follow '0'");

0 commit comments

Comments
 (0)