Skip to content

Commit f4790b9

Browse files
committed
simplify space check
1 parent a13020a commit f4790b9

3 files changed

Lines changed: 27 additions & 27 deletions

File tree

core/src/main/java/com/alibaba/fastjson2/JSONReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public abstract class JSONReader
5252
static final byte JSON_TYPE_NaN = 14;
5353

5454
static final char EOI = 0x1A;
55-
static final long SPACE = (1L << ' ') | (1L << '\n') | (1L << '\r') | (1L << '\f') | (1L << '\t') | (1L << '\b');
55+
static final long SPACE = 1L | (1L << ' ') | (1L << '\n') | (1L << '\r') | (1L << '\f') | (1L << '\t') | (1L << '\b');
5656

5757
static final boolean[] INT_VALUE_END = new boolean[256];
5858
static {

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF16.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public byte[] readHex() {
143143
comma = true;
144144

145145
ch = offset == end ? EOI : chars[offset++];
146-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
146+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
147147
ch = offset == end ? EOI : chars[offset++];
148148
}
149149
this.offset = offset;
@@ -512,7 +512,7 @@ public boolean nextIfMatch(char m) {
512512
}
513513

514514
ch = offset == end ? EOI : chars[offset++];
515-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
515+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
516516
ch = offset == end ? EOI : chars[offset++];
517517
}
518518
this.offset = offset;
@@ -539,7 +539,7 @@ public boolean nextIfComma() {
539539
}
540540

541541
ch = offset == end ? EOI : chars[offset++];
542-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
542+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
543543
ch = offset == end ? EOI : chars[offset++];
544544
}
545545

@@ -561,7 +561,7 @@ public boolean nextIfArrayStart() {
561561
char[] chars = this.chars;
562562
int offset = this.offset;
563563
ch = offset == end ? EOI : chars[offset++];
564-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
564+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
565565
ch = offset == end ? EOI : chars[offset++];
566566
}
567567

@@ -583,14 +583,14 @@ public boolean nextIfArrayEnd() {
583583
int offset = this.offset;
584584
char[] chars = this.chars;
585585
ch = offset == end ? EOI : chars[offset++];
586-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
586+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
587587
ch = offset == end ? EOI : chars[offset++];
588588
}
589589

590590
if (ch == ',') {
591591
comma = true;
592592
ch = offset == end ? EOI : chars[offset++];
593-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
593+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
594594
ch = offset == end ? EOI : chars[offset++];
595595
}
596596
}
@@ -824,7 +824,7 @@ public boolean nextIfObjectStart() {
824824
char[] chars = this.chars;
825825
int offset = this.offset;
826826
ch = offset == end ? EOI : chars[offset++];
827-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
827+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
828828
ch = offset == end ? EOI : chars[offset++];
829829
}
830830

@@ -847,14 +847,14 @@ public boolean nextIfObjectEnd() {
847847
int offset = this.offset;
848848
char[] chars = this.chars;
849849
ch = offset == end ? EOI : chars[offset++];
850-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
850+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
851851
ch = offset == end ? EOI : chars[offset++];
852852
}
853853

854854
if (ch == ',') {
855855
comma = true;
856856
ch = offset == end ? EOI : chars[offset++];
857-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
857+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
858858
ch = offset == end ? EOI : chars[offset++];
859859
}
860860
}
@@ -873,7 +873,7 @@ public void next() {
873873
int offset = this.offset;
874874
final char[] chars = this.chars;
875875
char ch = offset >= end ? EOI : chars[offset++];
876-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
876+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
877877
ch = offset == end ? EOI : chars[offset++];
878878
}
879879
this.offset = offset;
@@ -888,7 +888,7 @@ public final void nextWithoutComment() {
888888
int offset = this.offset;
889889
final char[] chars = this.chars;
890890
char ch = offset >= end ? EOI : chars[offset++];
891-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
891+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
892892
ch = offset == end ? EOI : chars[offset++];
893893
}
894894
this.offset = offset;
@@ -4711,7 +4711,7 @@ public final OffsetDateTime readOffsetDateTime() {
47114711
}
47124712
if (ch == quote) {
47134713
ch = offset >= end ? EOI : chars[offset++];
4714-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
4714+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
47154715
ch = offset == end ? EOI : chars[offset++];
47164716
}
47174717
if (comma = (ch == ',')) {

core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class JSONReaderUTF8
9898
this.end = length;
9999

100100
int ch = offset >= end ? EOI : bytes[offset++];
101-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
101+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
102102
ch = offset == end ? EOI : bytes[offset++];
103103
}
104104

@@ -124,7 +124,7 @@ class JSONReaderUTF8
124124
this.end = offset + length;
125125

126126
int ch = offset >= end ? EOI : bytes[offset++];
127-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
127+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
128128
ch = offset == end ? EOI : bytes[offset++];
129129
}
130130

@@ -235,7 +235,7 @@ public boolean nextIfMatch(char m) {
235235
}
236236

237237
ch = offset == end ? EOI : bytes[offset++];
238-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
238+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
239239
ch = offset == end ? EOI : bytes[offset++];
240240
}
241241

@@ -269,7 +269,7 @@ public boolean nextIfComma() {
269269
}
270270

271271
ch = offset == end ? EOI : bytes[offset++];
272-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
272+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
273273
ch = offset == end ? EOI : bytes[offset++];
274274
}
275275

@@ -297,7 +297,7 @@ public boolean nextIfArrayStart() {
297297
final byte[] bytes = this.bytes;
298298
int offset = this.offset;
299299
ch = offset == end ? EOI : bytes[offset++];
300-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
300+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
301301
ch = offset == end ? EOI : bytes[offset++];
302302
}
303303

@@ -325,14 +325,14 @@ public boolean nextIfArrayEnd() {
325325
}
326326

327327
ch = offset == end ? EOI : bytes[offset++];
328-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
328+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
329329
ch = offset == end ? EOI : bytes[offset++];
330330
}
331331

332332
if (ch == ',') {
333333
comma = true;
334334
ch = offset == end ? EOI : bytes[offset++];
335-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
335+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
336336
ch = offset == end ? EOI : bytes[offset++];
337337
}
338338
}
@@ -409,7 +409,7 @@ public boolean nextIfObjectStart() {
409409
final byte[] bytes = this.bytes;
410410
int offset = this.offset;
411411
ch = offset == end ? EOI : bytes[offset++];
412-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
412+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
413413
ch = offset == end ? EOI : bytes[offset++];
414414
}
415415

@@ -438,14 +438,14 @@ public boolean nextIfObjectEnd() {
438438
}
439439

440440
ch = offset == end ? EOI : bytes[offset++];
441-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
441+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
442442
ch = offset == end ? EOI : bytes[offset++];
443443
}
444444

445445
if (ch == ',') {
446446
comma = true;
447447
ch = offset == end ? EOI : bytes[offset++];
448-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
448+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
449449
ch = offset == end ? EOI : bytes[offset++];
450450
}
451451
}
@@ -469,7 +469,7 @@ public void next() {
469469
final byte[] bytes = this.bytes;
470470
int offset = this.offset;
471471
int ch = offset >= end ? EOI : bytes[offset++];
472-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
472+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
473473
ch = offset == end ? EOI : bytes[offset++];
474474
}
475475

@@ -490,7 +490,7 @@ public final void nextWithoutComment() {
490490
final byte[] bytes = this.bytes;
491491
int offset = this.offset;
492492
int ch = offset >= end ? EOI : bytes[offset++];
493-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
493+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
494494
ch = offset == end ? EOI : bytes[offset++];
495495
}
496496

@@ -3862,7 +3862,7 @@ public final OffsetDateTime readOffsetDateTime() {
38623862
}
38633863
if (ch == quote) {
38643864
ch = offset >= end ? EOI : bytes[offset++];
3865-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
3865+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
38663866
ch = offset == end ? EOI : bytes[offset++];
38673867
}
38683868
if (comma = (ch == ',')) {
@@ -4980,7 +4980,7 @@ public final byte[] readHex() {
49804980

49814981
comma = true;
49824982
ch = offset == end ? EOI : bytes[offset++];
4983-
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
4983+
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
49844984
ch = offset == end ? EOI : bytes[offset++];
49854985
}
49864986
this.offset = offset;

0 commit comments

Comments
 (0)