Skip to content

Commit 0841d0d

Browse files
committed
More efficient reading of time-zone offsets in java.time.* types for JVMs and Scala Native
1 parent 4e2b7e7 commit 0841d0d

File tree

2 files changed

+12
-12
lines changed
  • jsoniter-scala-core

2 files changed

+12
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,16 +3751,16 @@ final class JsonReader private[jsoniter_scala](
37513751

37523752
private[this] def toZoneOffset(sb: Byte, offsetTotal: Int): ZoneOffset = {
37533753
var qp = offsetTotal * 37283
3754+
val s = sb << 29 >> 31
37543755
if ((qp & 0x1FF8000) == 0) { // check if offsetTotal divisible by 900
3755-
qp >>>= 25 // divide offsetTotal by 900
3756-
if (sb == '-') qp = -qp
3757-
var zoneOffset = zoneOffsets(qp + 72)
3756+
qp = ((qp >>> 25) ^ s) - s + 72 // divide offsetTotal by 900
3757+
var zoneOffset = zoneOffsets(qp)
37583758
if (zoneOffset eq null) {
3759-
zoneOffset = ZoneOffset.ofTotalSeconds(if (sb == '-') -offsetTotal else offsetTotal)
3760-
zoneOffsets(qp + 72) = zoneOffset
3759+
zoneOffset = ZoneOffset.ofTotalSeconds((offsetTotal ^ s) - s)
3760+
zoneOffsets(qp) = zoneOffset
37613761
}
37623762
zoneOffset
3763-
} else ZoneOffset.ofTotalSeconds(if (sb == '-') -offsetTotal else offsetTotal)
3763+
} else ZoneOffset.ofTotalSeconds((offsetTotal ^ s) - s)
37643764
}
37653765

37663766
private[this] def epochDay(year: Int, month: Int, day: Int): Long =

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,16 +3747,16 @@ final class JsonReader private[jsoniter_scala](
37473747

37483748
private[this] def toZoneOffset(sb: Byte, offsetTotal: Int): ZoneOffset = {
37493749
var qp = offsetTotal * 37283
3750+
val s = sb << 29 >> 31
37503751
if ((qp & 0x1FF8000) == 0) { // check if offsetTotal divisible by 900
3751-
qp >>>= 25 // divide offsetTotal by 900
3752-
if (sb == '-') qp = -qp
3753-
var zoneOffset = zoneOffsets(qp + 72)
3752+
qp = ((qp >>> 25) ^ s) - s + 72 // divide offsetTotal by 900
3753+
var zoneOffset = zoneOffsets(qp)
37543754
if (zoneOffset eq null) {
3755-
zoneOffset = ZoneOffset.ofTotalSeconds(if (sb == '-') -offsetTotal else offsetTotal)
3756-
zoneOffsets(qp + 72) = zoneOffset
3755+
zoneOffset = ZoneOffset.ofTotalSeconds((offsetTotal ^ s) - s)
3756+
zoneOffsets(qp) = zoneOffset
37573757
}
37583758
zoneOffset
3759-
} else ZoneOffset.ofTotalSeconds(if (sb == '-') -offsetTotal else offsetTotal)
3759+
} else ZoneOffset.ofTotalSeconds((offsetTotal ^ s) - s)
37603760
}
37613761

37623762
private[this] def epochDay(year: Int, month: Int, day: Int): Long =

0 commit comments

Comments
 (0)