Skip to content

Commit

Permalink
More efficient parsing of small BigDecimal values for JVMs and Scal…
Browse files Browse the repository at this point in the history
…a Native
  • Loading branch information
plokhotnyuk committed Dec 28, 2022
1 parent 0d60ffe commit 1e1e97a
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1735,53 +1735,69 @@ final class JsonReader private[jsoniter_scala](
}) leadingZeroError(pos - 1)
} else {
digits -= pos
var m, bs = 0L
while ((pos + 7 < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos + 7 < tail
}) && {
val bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
((bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L) == 0
bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
m = (bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L
m == 0
}) pos += 8
while ((pos < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
if (m == 0) {
while ((pos < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
} else {
val offset = java.lang.Long.numberOfTrailingZeros(m) >> 3
pos += offset
b = (bs >> (offset << 3)).toByte
}
digits += pos
}
var fracLen, scale = 0
if (digits >= digitsLimit) digitsLimitError(pos + digitsLimit - digits - 1)
if (b == '.') {
pos += 1
fracLen -= pos
var m, bs = 0L
while ((pos + 7 < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos + 7 < tail
}) && {
val bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
((bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L) == 0
bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
m = (bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L
m == 0
}) pos += 8
while ((pos < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
if (m == 0) {
while ((pos < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
} else {
val offset = java.lang.Long.numberOfTrailingZeros(m) >> 3
pos += offset
b = (bs >> (offset << 3)).toByte
}
fracLen += pos
digits += fracLen
if (fracLen == 0) numberError(pos)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1732,53 +1732,69 @@ final class JsonReader private[jsoniter_scala](
}) leadingZeroError(pos - 1)
} else {
digits -= pos
var m, bs = 0L
while ((pos + 7 < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos + 7 < tail
}) && {
val bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
((bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L) == 0
bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
m = (bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L
m == 0
}) pos += 8
while ((pos < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
if (m == 0) {
while ((pos < tail || {
digits += pos
pos = loadMore(pos)
digits -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
} else {
val offset = java.lang.Long.numberOfTrailingZeros(m) >> 3
pos += offset
b = (bs >> (offset << 3)).toByte
}
digits += pos
}
var fracLen, scale = 0
if (digits >= digitsLimit) digitsLimitError(pos + digitsLimit - digits - 1)
if (b == '.') {
pos += 1
fracLen -= pos
var m, bs = 0L
while ((pos + 7 < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos + 7 < tail
}) && {
val bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
((bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L) == 0
bs = ByteArrayAccess.getLong(buf, pos) // Based on the fast parsing of numbers by 8-byte words: https://github.com/wrandelshofer/FastDoubleParser/blob/0903817a765b25e654f02a5a9d4f1476c98a80c9/src/main/java/ch.randelshofer.fastdoubleparser/ch/randelshofer/fastdoubleparser/FastDoubleSimd.java#L114-L130
m = (bs + 0x4646464646464646L | bs - 0x3030303030303030L) & 0x8080808080808080L
m == 0
}) pos += 8
while ((pos < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
if (m == 0) {
while ((pos < tail || {
fracLen += pos
pos = loadMore(pos)
fracLen -= pos
buf = this.buf
pos < tail
}) && {
b = buf(pos)
b >= '0' && b <= '9'
}) pos += 1
} else {
val offset = java.lang.Long.numberOfTrailingZeros(m) >> 3
pos += offset
b = (bs >> (offset << 3)).toByte
}
fracLen += pos
digits += fracLen
if (fracLen == 0) numberError(pos)
Expand Down

0 comments on commit 1e1e97a

Please sign in to comment.