Skip to content

Commit 03c272b

Browse files
committed
More efficient writing Double and java.time.Duration values using Scala.is
1 parent e01e14b commit 03c272b

File tree

1 file changed

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

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,12 +1784,12 @@ final class JsonWriter private[jsoniter_scala](
17841784
var q = hours.toInt
17851785
var lastPos = pos
17861786
if (hours == q) {
1787-
lastPos += digitCount(hours)
1787+
lastPos += digitCount(q)
17881788
pos = lastPos
17891789
} else {
17901790
val q1 = hours / 100000000
17911791
q = q1.toInt
1792-
lastPos += digitCount(q1)
1792+
lastPos += digitCount(q)
17931793
pos = write8Digits((hours - q1 * 100000000).toInt, lastPos, buf, ds)
17941794
}
17951795
writePositiveIntDigits(q, lastPos, buf, ds)
@@ -2559,8 +2559,9 @@ final class JsonWriter private[jsoniter_scala](
25592559
((b >>> 32) + (x1 + x2) * (y1 + y2) - b - a >>> 32) + a
25602560
}
25612561

2562-
private[this] def digitCount(q0: Long): Int =
2563-
if (q0.toInt == q0) digitCount(q0.toInt)
2562+
private[this] def digitCount(q0: Long): Int = {
2563+
val q = q0.toInt
2564+
if (q == q0) digitCount(q)
25642565
else if (q0 < 10000000000L) {
25652566
if (q0 < 1000000000L) 9
25662567
else 10
@@ -2573,10 +2574,8 @@ final class JsonWriter private[jsoniter_scala](
25732574
} else if (q0 < 10000000000000000L) {
25742575
if (q0 < 1000000000000000L) 15
25752576
else 16
2576-
} else {
2577-
if (q0 < 100000000000000000L) 17
2578-
else 18
2579-
}
2577+
} else 17
2578+
}
25802579

25812580
private[this] def digitCount(x: Int): Int =
25822581
if (x < 100) (9 - x >>> 31) + 1

0 commit comments

Comments
 (0)