Skip to content

Commit d4da58e

Browse files
committed
More efficient writing of Float, Double, and java.time.Duration values using Scala.js
1 parent c51c46a commit d4da58e

File tree

1 file changed

+7
-2
lines changed
  • jsoniter-scala-core/js/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,9 @@ final class JsonWriter private[jsoniter_scala](
17801780
var hours = 0L
17811781
var secsOfHour = effectiveTotalSecs.toInt
17821782
if (effectiveTotalSecs >= 3600) {
1783-
hours = effectiveTotalSecs / 3600
1783+
hours =
1784+
if (effectiveTotalSecs >= 4503599627370496L) effectiveTotalSecs / 3600
1785+
else (effectiveTotalSecs * 2.777777777777778E-4).toLong
17841786
secsOfHour = (effectiveTotalSecs - (hours << 12) + (hours << 9) - (hours << 4)).toInt // (effectiveTotalSecs - hours * 3600).toInt
17851787
}
17861788
val minutes = secsOfHour * 17477 >> 20 // divide a small positive int by 60
@@ -1797,7 +1799,7 @@ final class JsonWriter private[jsoniter_scala](
17971799
lastPos += digitCount(q)
17981800
pos = lastPos
17991801
} else {
1800-
q = ((hours >>> 8) * 2.56e-6).toInt // divide a medium positive long by 100000000
1802+
q = (hours * 1e-8).toInt // divide a medium positive long by 100000000
18011803
lastPos += digitCount(q)
18021804
pos = write8Digits((hours - q * 100000000L).toInt, lastPos, buf, ds)
18031805
}
@@ -2641,6 +2643,7 @@ final class JsonWriter private[jsoniter_scala](
26412643
else if (x < 100000000) (9999999 - x >>> 31) + 7
26422644
else (999999999 - x >>> 31) + 9
26432645

2646+
@inline
26442647
private[this] def writeSignificantFractionDigits(x: Long, p: Int, pl: Int, buf: Array[Byte], ds: Array[Short]): Int = {
26452648
var q0 = x.toInt
26462649
var pos = p
@@ -2661,6 +2664,7 @@ final class JsonWriter private[jsoniter_scala](
26612664
writeSignificantFractionDigits(q0, pos, posLim, buf, ds)
26622665
}
26632666

2667+
@inline
26642668
private[this] def writeSignificantFractionDigits(q: Int, p: Int, posLim: Int, buf: Array[Byte], ds: Array[Short]): Int = {
26652669
var q0 = q
26662670
var q1, r1 = 0
@@ -2684,6 +2688,7 @@ final class JsonWriter private[jsoniter_scala](
26842688
lastPos
26852689
}
26862690

2691+
@inline
26872692
private[this] def writeFractionDigits(q: Int, p: Int, posLim: Int, buf: Array[Byte], ds: Array[Short]): Unit = {
26882693
var q0 = q
26892694
var pos = p

0 commit comments

Comments
 (0)