Skip to content

Commit 63ef6c4

Browse files
committed
Clean up of reader code
1 parent 0b113f6 commit 63ef6c4

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

core/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,15 @@ final class JsonReader private[jsoniter_scala](
792792
var pos = head
793793
if (b >= '0' && b <= '9') {
794794
var x = '0' - b
795+
val isZeroFirst = isToken && x == 0
795796
while ((pos < tail || {
796797
pos = loadMore(pos)
797798
pos < tail
798799
}) && {
799800
b = buf(pos)
800801
b >= '0' && b <= '9'
801802
}) pos = {
802-
if (isToken && x == 0) leadingZeroError(pos - 1)
803+
if (isZeroFirst) leadingZeroError(pos - 1)
803804
x = x * 10 + ('0' - b)
804805
if (x < -128) byteOverflowError(pos)
805806
pos + 1
@@ -819,14 +820,15 @@ final class JsonReader private[jsoniter_scala](
819820
var pos = head
820821
if (b >= '0' && b <= '9') {
821822
var x = '0' - b
823+
val isZeroFirst = isToken && x == 0
822824
while ((pos < tail || {
823825
pos = loadMore(pos)
824826
pos < tail
825827
}) && {
826828
b = buf(pos)
827829
b >= '0' && b <= '9'
828830
}) pos = {
829-
if (isToken && x == 0) leadingZeroError(pos - 1)
831+
if (isZeroFirst) leadingZeroError(pos - 1)
830832
x = x * 10 + ('0' - b)
831833
if (x < -32768) shortOverflowError(pos)
832834
pos + 1
@@ -846,14 +848,15 @@ final class JsonReader private[jsoniter_scala](
846848
var pos = head
847849
if (b >= '0' && b <= '9') {
848850
var x = '0' - b
851+
val isZeroFirst = isToken && x == 0
849852
while ((pos < tail || {
850853
pos = loadMore(pos)
851854
pos < tail
852855
}) && {
853856
b = buf(pos)
854857
b >= '0' && b <= '9'
855858
}) pos = {
856-
if (isToken && x == 0) leadingZeroError(pos - 1)
859+
if (isZeroFirst) leadingZeroError(pos - 1)
857860
if (x < -214748364) intOverflowError(pos)
858861
x = x * 10 + ('0' - b)
859862
if (x > 0) intOverflowError(pos)
@@ -874,14 +877,15 @@ final class JsonReader private[jsoniter_scala](
874877
var pos = head
875878
if (b >= '0' && b <= '9') {
876879
var x: Long = '0' - b
880+
val isZeroFirst = isToken && x == 0
877881
while ((pos < tail || {
878882
pos = loadMore(pos)
879883
pos < tail
880884
}) && {
881885
b = buf(pos)
882886
b >= '0' && b <= '9'
883887
}) pos = {
884-
if (isToken && x == 0) leadingZeroError(pos - 1)
888+
if (isZeroFirst) leadingZeroError(pos - 1)
885889
if (x < -922337203685477580L) longOverflowError(pos)
886890
x = x * 10 + ('0' - b)
887891
if (x > 0) longOverflowError(pos)
@@ -905,6 +909,7 @@ final class JsonReader private[jsoniter_scala](
905909
var pos = head
906910
if (b >= '0' && b <= '9') {
907911
var posMan: Long = b - '0'
912+
val isZeroFirst = isToken && posMan == 0
908913
var manExp = 0
909914
var posExp = 0
910915
var isExpNeg = false
@@ -915,14 +920,13 @@ final class JsonReader private[jsoniter_scala](
915920
b = buf(pos)
916921
b >= '0' && b <= '9'
917922
}) pos = {
918-
if (isToken && posMan == 0) leadingZeroError(pos - 1)
923+
if (isZeroFirst) leadingZeroError(pos - 1)
919924
if (posMan < 4503599627370496L) posMan = posMan * 10 + (b - '0')
920925
else manExp += 1
921926
pos + 1
922927
}
923928
if (b == '.') {
924-
head = pos + 1
925-
b = nextByte(head)
929+
b = nextByte(pos + 1)
926930
pos = head
927931
if (b >= '0' && b <= '9') {
928932
if (posMan < 4503599627370496L) {
@@ -945,8 +949,7 @@ final class JsonReader private[jsoniter_scala](
945949
} else numberError(pos - 1)
946950
}
947951
if ((b | 0x20) == 'e') {
948-
head = pos + 1
949-
b = nextByte(head)
952+
b = nextByte(pos + 1)
950953
if (b == '-' || b == '+') {
951954
isExpNeg = b == '-'
952955
b = nextByte(head)
@@ -1056,8 +1059,7 @@ final class JsonReader private[jsoniter_scala](
10561059
pos + 1
10571060
}
10581061
if (b == '.') {
1059-
head = pos + 1
1060-
b = nextByte(head)
1062+
b = nextByte(pos + 1)
10611063
pos = head
10621064
if (b >= '0' && b <= '9') {
10631065
while ((pos < tail || {
@@ -1070,11 +1072,8 @@ final class JsonReader private[jsoniter_scala](
10701072
} else numberError(pos - 1)
10711073
}
10721074
if ((b | 0x20) == 'e') {
1073-
head = pos + 1
1074-
b = nextByte(head)
1075-
if (b == '-' || b == '+') {
1076-
b = nextByte(head)
1077-
}
1075+
b = nextByte(pos + 1)
1076+
if (b == '-' || b == '+') b = nextByte(head)
10781077
pos = head
10791078
if (b >= '0' && b <= '9') {
10801079
while ((pos < tail || {

0 commit comments

Comments
 (0)