Skip to content

Commit 7327bd2

Browse files
committed
More efficient parsing of java.time.Duration values without nanoseconds
1 parent f68d81e commit 7327bd2

File tree

3 files changed

+6
-3
lines changed
  • jsoniter-scala-core

3 files changed

+6
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,7 +2952,8 @@ final class JsonReader private[jsoniter_scala](
29522952
b = nextByte(head)
29532953
} else if (state == 3) tokenError('"')
29542954
}
2955-
Duration.ofSeconds(seconds, nano.toLong)
2955+
if (nano == 0) Duration.ofSeconds(seconds)
2956+
else Duration.ofSeconds(seconds, nano.toLong)
29562957
}
29572958

29582959
private[this] def sumSeconds(s1: Long, s2: Long, pos: Int): Long = {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2999,7 +2999,8 @@ final class JsonReader private[jsoniter_scala](
29992999
b = nextByte(head)
30003000
} else if (state == 3) tokenError('"')
30013001
}
3002-
Duration.ofSeconds(seconds, nano.toLong)
3002+
if (nano == 0) Duration.ofSeconds(seconds)
3003+
else Duration.ofSeconds(seconds, nano.toLong)
30033004
}
30043005

30053006
private[this] def sumSeconds(s1: Long, s2: Long, pos: Int): Long = {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2995,7 +2995,8 @@ final class JsonReader private[jsoniter_scala](
29952995
b = nextByte(head)
29962996
} else if (state == 3) tokenError('"')
29972997
}
2998-
Duration.ofSeconds(seconds, nano.toLong)
2998+
if (nano == 0) Duration.ofSeconds(seconds)
2999+
else Duration.ofSeconds(seconds, nano.toLong)
29993000
}
30003001

30013002
private[this] def sumSeconds(s1: Long, s2: Long, pos: Int): Long = {

0 commit comments

Comments
 (0)