Skip to content

Commit 8192daf

Browse files
committed
Code clean up
1 parent a4b18fc commit 8192daf

File tree

3 files changed

+25
-30
lines changed
  • jsoniter-scala-core

3 files changed

+25
-30
lines changed

jsoniter-scala-core/js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -2106,10 +2106,10 @@ final class JsonReader private[jsoniter_scala](
21062106
var b =
21072107
if (isToken) nextToken(head)
21082108
else nextByte(head)
2109-
var isPos = true
2109+
var s = -1
21102110
if (b == '-') {
21112111
b = nextByte(head)
2112-
isPos = false
2112+
s = 0
21132113
}
21142114
if (b < '0' || b > '9') numberError()
21152115
var x = '0' - b
@@ -2132,11 +2132,10 @@ final class JsonReader private[jsoniter_scala](
21322132
pos += 1
21332133
}
21342134
head = pos
2135+
x ^= s
2136+
x -= s
21352137
if ((b | 0x20) == 'e' || b == '.') numberError(pos)
2136-
if (isPos) {
2137-
if (x == -2147483648) intOverflowError(pos - 1)
2138-
x = -x
2139-
}
2138+
if ((s & x) == -2147483648) intOverflowError(pos - 1)
21402139
}
21412140
x
21422141
}

jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

+10-12
Original file line numberDiff line numberDiff line change
@@ -2068,10 +2068,10 @@ final class JsonReader private[jsoniter_scala](
20682068
var b =
20692069
if (isToken) nextToken(head)
20702070
else nextByte(head)
2071-
var isPos = true
2071+
var s = -1
20722072
if (b == '-') {
20732073
b = nextByte(head)
2074-
isPos = false
2074+
s = 0
20752075
}
20762076
if (b < '0' || b > '9') numberError()
20772077
var x = '0' - b
@@ -2094,11 +2094,10 @@ final class JsonReader private[jsoniter_scala](
20942094
pos += 1
20952095
}
20962096
head = pos
2097+
x ^= s
2098+
x -= s
20972099
if ((b | 0x20) == 'e' || b == '.') numberError(pos)
2098-
if (isPos) {
2099-
if (x == -2147483648) intOverflowError(pos - 1)
2100-
x = -x
2101-
}
2100+
if ((s & x) == -2147483648) intOverflowError(pos - 1)
21022101
}
21032102
x
21042103
}
@@ -2107,10 +2106,10 @@ final class JsonReader private[jsoniter_scala](
21072106
var b =
21082107
if (isToken) nextToken(head)
21092108
else nextByte(head)
2110-
var isPos = true
2109+
var s = -1L
21112110
if (b == '-') {
21122111
b = nextByte(head)
2113-
isPos = false
2112+
s = 0L
21142113
}
21152114
if (b < '0' || b > '9') numberError()
21162115
var x = ('0' - b).toLong
@@ -2151,11 +2150,10 @@ final class JsonReader private[jsoniter_scala](
21512150
pos += 1
21522151
}
21532152
head = pos
2153+
x ^= s
2154+
x -= s
21542155
if ((b | 0x20) == 'e' || b == '.') numberError(pos)
2155-
if (isPos) {
2156-
if (x == -9223372036854775808L) longOverflowError(pos - 1)
2157-
x = -x
2158-
}
2156+
if ((s & x) == -9223372036854775808L) longOverflowError(pos - 1)
21592157
}
21602158
x
21612159
}

jsoniter-scala-core/native/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

+10-12
Original file line numberDiff line numberDiff line change
@@ -2068,10 +2068,10 @@ final class JsonReader private[jsoniter_scala](
20682068
var b =
20692069
if (isToken) nextToken(head)
20702070
else nextByte(head)
2071-
var isPos = true
2071+
var s = -1
20722072
if (b == '-') {
20732073
b = nextByte(head)
2074-
isPos = false
2074+
s = 0
20752075
}
20762076
if (b < '0' || b > '9') numberError()
20772077
var x = '0' - b
@@ -2094,11 +2094,10 @@ final class JsonReader private[jsoniter_scala](
20942094
pos += 1
20952095
}
20962096
head = pos
2097+
x ^= s
2098+
x -= s
20972099
if ((b | 0x20) == 'e' || b == '.') numberError(pos)
2098-
if (isPos) {
2099-
if (x == -2147483648) intOverflowError(pos - 1)
2100-
x = -x
2101-
}
2100+
if ((s & x) == -2147483648) intOverflowError(pos - 1)
21022101
}
21032102
x
21042103
}
@@ -2107,10 +2106,10 @@ final class JsonReader private[jsoniter_scala](
21072106
var b =
21082107
if (isToken) nextToken(head)
21092108
else nextByte(head)
2110-
var isPos = true
2109+
var s = -1L
21112110
if (b == '-') {
21122111
b = nextByte(head)
2113-
isPos = false
2112+
s = 0L
21142113
}
21152114
if (b < '0' || b > '9') numberError()
21162115
var x = ('0' - b).toLong
@@ -2151,11 +2150,10 @@ final class JsonReader private[jsoniter_scala](
21512150
pos += 1
21522151
}
21532152
head = pos
2153+
x ^= s
2154+
x -= s
21542155
if ((b | 0x20) == 'e' || b == '.') numberError(pos)
2155-
if (isPos) {
2156-
if (x == -9223372036854775808L) longOverflowError(pos - 1)
2157-
x = -x
2158-
}
2156+
if ((s & x) == -9223372036854775808L) longOverflowError(pos - 1)
21592157
}
21602158
x
21612159
}

0 commit comments

Comments
 (0)