Skip to content

Commit 4b8c71b

Browse files
committed
optimize skip
1 parent a2e87ca commit 4b8c71b

6 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/main/java/com/jsoniter/IterImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ public static Any readAny(JsonIterator iter) throws IOException {
198198
return Any.lazyLong(iter.buf, start, iter.head);
199199
}
200200
case 't':
201-
skipUntilBreak(iter);
201+
skipFixedBytes(iter, 3);
202202
return Any.wrap(true);
203203
case 'f':
204-
skipUntilBreak(iter);
204+
skipFixedBytes(iter, 4);
205205
return Any.wrap(false);
206206
case 'n':
207-
skipUntilBreak(iter);
207+
skipFixedBytes(iter, 3);
208208
return Any.wrap((Object) null);
209209
case '[':
210210
skipArray(iter);

src/main/java/com/jsoniter/IterImplForStreaming.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ public static Any readAny(JsonIterator iter) throws IOException {
336336
return Any.lazyLong(copied, 0, copied.length);
337337
}
338338
case 't':
339-
skipUntilBreak(iter);
339+
skipFixedBytes(iter, 3);
340340
iter.skipStartedAt = -1;
341341
return Any.wrap(true);
342342
case 'f':
343-
skipUntilBreak(iter);
343+
skipFixedBytes(iter, 4);
344344
iter.skipStartedAt = -1;
345345
return Any.wrap(false);
346346
case 'n':
347-
skipUntilBreak(iter);
347+
skipFixedBytes(iter, 3);
348348
iter.skipStartedAt = -1;
349349
return Any.wrap((Object) null);
350350
case '[':

src/main/java/com/jsoniter/IterImplSkip.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public static final void skip(JsonIterator iter) throws IOException {
3333
case '7':
3434
case '8':
3535
case '9':
36+
IterImpl.skipUntilBreak(iter);
37+
return;
3638
case 't':
37-
case 'f':
3839
case 'n':
39-
IterImpl.skipUntilBreak(iter);
40+
IterImpl.skipFixedBytes(iter, 3); // true or null
41+
return;
42+
case 'f':
43+
IterImpl.skipFixedBytes(iter, 4); // false
4044
return;
4145
case '[':
4246
IterImpl.skipArray(iter);

src/main/java/com/jsoniter/IterImplString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static final String readString(JsonIterator iter) throws IOException {
6969
return IterImpl.readStringSlowPath(iter, j);
7070
}
7171
if (c == 'n') {
72-
IterImpl.skipUntilBreak(iter);
72+
IterImpl.skipFixedBytes(iter, 3);
7373
return null;
7474
}
7575
throw iter.reportError("readString", "expect n or \"");

src/main/java/com/jsoniter/JsonIterator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public final String readObject() throws IOException {
213213
byte c = IterImpl.nextToken(this);
214214
switch (c) {
215215
case 'n':
216-
IterImpl.skipUntilBreak(this);
216+
IterImpl.skipFixedBytes(this, 3);
217217
return null;
218218
case '{':
219219
c = IterImpl.nextToken(this);
@@ -279,7 +279,7 @@ public final Object read() throws IOException {
279279
case NUMBER:
280280
return readDouble();
281281
case NULL:
282-
IterImpl.skipUntilBreak(this);
282+
IterImpl.skipFixedBytes(this, 3);
283283
return null;
284284
case BOOLEAN:
285285
return readBoolean();

src/test/java/com/jsoniter/TestDemo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,13 @@ public void test_any_is_fun() throws IOException {
142142
assertEquals(Long.class, any.get(0, "score").object().getClass());
143143
any = JsonIterator.deserialize("[{'score':100}, {'score':102}]".replace('\'', '"'));
144144
assertEquals(ValueType.INVALID, any.get(0, "score", "number").valueType());
145+
any = JsonIterator.deserialize("[{'score':100}, {'score':102}]".replace('\'', '"'));
146+
for (Any record : any) {
147+
Any.EntryIterator entries = record.entries();
148+
while (entries.next()) {
149+
System.out.println(entries.key());
150+
System.out.println(entries.value());
151+
}
152+
}
145153
}
146154
}

0 commit comments

Comments
 (0)