Skip to content

Commit 4fbc4de

Browse files
committed
Code clean up
1 parent 24e10ba commit 4fbc4de

File tree

4 files changed

+47
-45
lines changed

4 files changed

+47
-45
lines changed

build.sbt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ lazy val publishSettings = Seq(
8686
},
8787
mimaBinaryIssueFilters := Seq( // internal API to ignore
8888
ProblemFilters.exclude[DirectMissingMethodProblem]("com.github.plokhotnyuk.jsoniter_scala.core.JsonReaderException.this"),
89-
ProblemFilters.exclude[DirectMissingMethodProblem]("com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker#Impl.com$github$plokhotnyuk$jsoniter_scala$macros$JsonCodecMaker$Impl$$genReadVal$default$4$1"),
90-
ProblemFilters.exclude[DirectMissingMethodProblem]("com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker#Impl.com$github$plokhotnyuk$jsoniter_scala$macros$JsonCodecMaker$Impl$$genWriteVal$default$4$1")
9189
),
9290
mimaReportSignatureProblems := true
9391
)
@@ -123,7 +121,12 @@ lazy val `jsoniter-scala-core` = crossProject(JVMPlatform, JSPlatform)
123121
.distinct
124122
}
125123
})
126-
).jsSettings(
124+
)
125+
126+
lazy val `jsoniter-scala-coreJVM` = `jsoniter-scala-core`.jvm
127+
128+
lazy val `jsoniter-scala-coreJS` = `jsoniter-scala-core`.js
129+
.settings(
127130
libraryDependencies ++= Seq(
128131
"io.github.cquiroz" %%% "scala-java-time" % "2.0.0",
129132
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.0.0"
@@ -132,10 +135,6 @@ lazy val `jsoniter-scala-core` = crossProject(JVMPlatform, JSPlatform)
132135
coverageEnabled := false // FIXME: No support for Scala.js 1.0 yet, see https://github.com/scoverage/scalac-scoverage-plugin/pull/287
133136
)
134137

135-
lazy val `jsoniter-scala-coreJVM` = `jsoniter-scala-core`.jvm
136-
137-
lazy val `jsoniter-scala-coreJS` = `jsoniter-scala-core`.js
138-
139138
lazy val `jsoniter-scala-macros` = crossProject(JVMPlatform, JSPlatform)
140139
.crossType(CrossType.Full)
141140
.dependsOn(`jsoniter-scala-core`)
@@ -148,14 +147,15 @@ lazy val `jsoniter-scala-macros` = crossProject(JVMPlatform, JSPlatform)
148147
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
149148
"org.scalatest" %%% "scalatest" % "3.1.2" % Test
150149
)
151-
).jsSettings(
152-
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
153-
coverageEnabled := false // FIXME: No support for Scala.js 1.0 yet, see https://github.com/scoverage/scalac-scoverage-plugin/pull/287
154150
)
155151

156152
lazy val `jsoniter-scala-macrosJVM` = `jsoniter-scala-macros`.jvm
157153

158154
lazy val `jsoniter-scala-macrosJS` = `jsoniter-scala-macros`.js
155+
.settings(
156+
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
157+
coverageEnabled := false // FIXME: No support for Scala.js 1.0 yet, see https://github.com/scoverage/scalac-scoverage-plugin/pull/287
158+
)
159159

160160
lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)
161161
.crossType(CrossType.Full)
@@ -194,16 +194,17 @@ lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)
194194
"org.openjdk.jmh" % "jmh-generator-reflection" % "1.23",
195195
"org.scalatest" %%% "scalatest" % "3.1.2" % Test
196196
)
197-
).jsSettings(
198-
libraryDependencies += "com.github.japgolly.scalajs-benchmark" %%% "benchmark" % "0.7.0",
199-
scalaJSUseMainModuleInitializer := true,
200-
scalaJSLinkerConfig ~= (_.withSemantics(Semantics.Defaults.withProductionMode(true)).withClosureCompiler(true)),
201-
mainClass in Compile := Some("com.github.plokhotnyuk.jsoniter_scala.benchmark.Main"),
202-
coverageEnabled := false // FIXME: No support for Scala.js 1.0 yet, see https://github.com/scoverage/scalac-scoverage-plugin/pull/287
203197
)
204198

205199
lazy val `jsoniter-scala-benchmarkJVM` = `jsoniter-scala-benchmark`.jvm
206200
.enablePlugins(JmhPlugin)
207201

208202
lazy val `jsoniter-scala-benchmarkJS` = `jsoniter-scala-benchmark`.js
209-
.enablePlugins(JSDependenciesPlugin)
203+
.enablePlugins(JSDependenciesPlugin)
204+
.settings(
205+
libraryDependencies += "com.github.japgolly.scalajs-benchmark" %%% "benchmark" % "0.7.0",
206+
scalaJSUseMainModuleInitializer := true,
207+
scalaJSLinkerConfig ~= (_.withSemantics(Semantics.Defaults.withProductionMode(true)).withClosureCompiler(true)),
208+
mainClass in Compile := Some("com.github.plokhotnyuk.jsoniter_scala.benchmark.Main"),
209+
coverageEnabled := false // FIXME: No support for Scala.js 1.0 yet, see https://github.com/scoverage/scalac-scoverage-plugin/pull/287
210+
)

jsoniter-scala-benchmark/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/benchmark/StringOfAsciiCharsBenchmark.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class StringOfAsciiCharsBenchmark extends CommonParams {
2525
while ({
2626
ch = ((j * 1498724053) % 128).toChar
2727
j += 1
28-
!JsonWriter.isNonEscapedAscii(ch) || ch == '~' // FIXME: Jsoniter(Java) uses hexadecimal escaping for `~`
28+
!JsonWriter.isNonEscapedAscii(ch)
2929
}) ()
3030
ch
3131
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ final class JsonReader private[jsoniter_scala](
16451645
}
16461646

16471647
private[this] def addExp(e2: Int, e10: Int): Int =
1648-
(e10 * 14267572527L >> 32).toInt + e2 + 1 // (e10 * Math.log(10) / Math.log(2)).toInt + e2 + 1
1648+
(e10 * 108853 >> 15) + e2 + 1 // (e10 * Math.log(10) / Math.log(2)).toInt + e2 + 1
16491649

16501650
private[this] def parseBigInt(isToken: Boolean, default: BigInt, digitsLimit: Int): BigInt = {
16511651
var b =
@@ -1843,14 +1843,14 @@ final class JsonReader private[jsoniter_scala](
18431843
}
18441844
var x2 =
18451845
(buf(pos) * 10 + buf(pos + 1)) * 10000000000000000L +
1846-
(buf(pos + 2) * 10 + buf(pos + 3)) * 100000000000000L +
1847-
(buf(pos + 4) * 10 + buf(pos + 5)) * 1000000000000L +
1848-
(buf(pos + 6) * 10 + buf(pos + 7)) * 10000000000L +
1849-
(buf(pos + 8) * 10 + buf(pos + 9)) * 100000000L +
1850-
(buf(pos + 10) * 10 + buf(pos + 11)) * 1000000 +
1846+
((buf(pos + 2) * 10 + buf(pos + 3)) * 1000000 +
1847+
(buf(pos + 4) * 10 + buf(pos + 5)) * 10000 +
1848+
(buf(pos + 6) * 10 + buf(pos + 7)) * 100 +
1849+
(buf(pos + 8) * 10 + buf(pos + 9))) * 100000000L +
1850+
((buf(pos + 10) * 10 + buf(pos + 11)) * 1000000 +
18511851
(buf(pos + 12) * 10 + buf(pos + 13)) * 10000 +
18521852
(buf(pos + 14) * 10 + buf(pos + 15)) * 100 +
1853-
buf(pos + 16) * 10 + buf(pos + 17) - 5333333333333333328L // 5333333333333333328L == '0' * 111111111111111111L
1853+
buf(pos + 16) * 10 + buf(pos + 17)) - 5333333333333333328L // 5333333333333333328L == '0' * 111111111111111111L
18541854
if (isNeg) {
18551855
x1 = -x1
18561856
x2 = -x2
@@ -1868,17 +1868,17 @@ final class JsonReader private[jsoniter_scala](
18681868
x = x * 10 + (buf(pos) - '0')
18691869
pos += 1
18701870
}
1871-
val lastWord = ((len * 445861642L) >>> 32).toInt // (len * log(10) / log (1L << 32)).toInt
1871+
val lastWord = ((len * 445861642L) >>> 32).toInt // (len * Math.log(10) / Math.log(1L << 32)).toInt
18721872
val numWords = lastWord + 1
18731873
val magWords = new Array[Int](numWords)
18741874
magWords(lastWord) = x.toInt
18751875
while (pos < limit) {
18761876
x =
18771877
(buf(pos) * 10 + buf(pos + 1)) * 10000000L +
1878-
(buf(pos + 2) * 10 + buf(pos + 3)) * 100000 +
1878+
((buf(pos + 2) * 10 + buf(pos + 3)) * 100000 +
18791879
(buf(pos + 4) * 10 + buf(pos + 5)) * 1000 +
18801880
(buf(pos + 6) * 10 + buf(pos + 7)) * 10 +
1881-
buf(pos + 8) - 5333333328L // 5333333328L == '0' * 111111111L
1881+
buf(pos + 8)) - 5333333328L // 5333333328L == '0' * 111111111L
18821882
var i = lastWord
18831883
while (i >= 0) {
18841884
val p = (magWords(i) & 0xFFFFFFFFL) * 1000000000 + x
@@ -2362,7 +2362,7 @@ final class JsonReader private[jsoniter_scala](
23622362
})
23632363

23642364
private[this] def dayOfYearForYearMonth(year: Int, month: Int): Int =
2365-
((month * 367 - 362) / 12) -
2365+
((month * 1002277 - 988622) >> 15) - // (month * 367 - 362) / 12
23662366
(if (month <= 2) 0
23672367
else if (isLeap(year)) 1
23682368
else 2)

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ final class JsonReader private[jsoniter_scala](
16391639
}
16401640

16411641
private[this] def addExp(e2: Int, e10: Int): Int =
1642-
(e10 * 14267572527L >> 32).toInt + e2 + 1 // (e10 * Math.log(10) / Math.log(2)).toInt + e2 + 1
1642+
(e10 * 108853 >> 15) + e2 + 1 // (e10 * Math.log(10) / Math.log(2)).toInt + e2 + 1
16431643

16441644
private[this] def parseBigInt(isToken: Boolean, default: BigInt, digitsLimit: Int): BigInt = {
16451645
var b =
@@ -1837,14 +1837,14 @@ final class JsonReader private[jsoniter_scala](
18371837
}
18381838
var x2 =
18391839
(buf(pos) * 10 + buf(pos + 1)) * 10000000000000000L +
1840-
(buf(pos + 2) * 10 + buf(pos + 3)) * 100000000000000L +
1841-
(buf(pos + 4) * 10 + buf(pos + 5)) * 1000000000000L +
1842-
(buf(pos + 6) * 10 + buf(pos + 7)) * 10000000000L +
1843-
(buf(pos + 8) * 10 + buf(pos + 9)) * 100000000L +
1844-
(buf(pos + 10) * 10 + buf(pos + 11)) * 1000000 +
1840+
((buf(pos + 2) * 10 + buf(pos + 3)) * 1000000 +
1841+
(buf(pos + 4) * 10 + buf(pos + 5)) * 10000 +
1842+
(buf(pos + 6) * 10 + buf(pos + 7)) * 100 +
1843+
(buf(pos + 8) * 10 + buf(pos + 9))) * 100000000L +
1844+
((buf(pos + 10) * 10 + buf(pos + 11)) * 1000000 +
18451845
(buf(pos + 12) * 10 + buf(pos + 13)) * 10000 +
18461846
(buf(pos + 14) * 10 + buf(pos + 15)) * 100 +
1847-
buf(pos + 16) * 10 + buf(pos + 17) - 5333333333333333328L // 5333333333333333328L == '0' * 111111111111111111L
1847+
buf(pos + 16) * 10 + buf(pos + 17)) - 5333333333333333328L // 5333333333333333328L == '0' * 111111111111111111L
18481848
if (isNeg) {
18491849
x1 = -x1
18501850
x2 = -x2
@@ -1862,17 +1862,17 @@ final class JsonReader private[jsoniter_scala](
18621862
x = x * 10 + (buf(pos) - '0')
18631863
pos += 1
18641864
}
1865-
val lastWord = ((len * 445861642L) >>> 32).toInt // (len * log(10) / log (1L << 32)).toInt
1865+
val lastWord = ((len * 445861642L) >>> 32).toInt // (len * Math.log(10) / Math.log(1L << 32)).toInt
18661866
val numWords = lastWord + 1
18671867
val magWords = new Array[Int](numWords)
18681868
magWords(lastWord) = x.toInt
18691869
while (pos < limit) {
18701870
x =
18711871
(buf(pos) * 10 + buf(pos + 1)) * 10000000L +
1872-
(buf(pos + 2) * 10 + buf(pos + 3)) * 100000 +
1872+
((buf(pos + 2) * 10 + buf(pos + 3)) * 100000 +
18731873
(buf(pos + 4) * 10 + buf(pos + 5)) * 1000 +
18741874
(buf(pos + 6) * 10 + buf(pos + 7)) * 10 +
1875-
buf(pos + 8) - 5333333328L // 5333333328L == '0' * 111111111L
1875+
buf(pos + 8)) - 5333333328L // 5333333328L == '0' * 111111111L
18761876
var i = lastWord
18771877
while (i >= 0) {
18781878
val p = (magWords(i) & 0xFFFFFFFFL) * 1000000000 + x
@@ -2331,16 +2331,17 @@ final class JsonReader private[jsoniter_scala](
23312331

23322332
private[this] def toZoneOffset(isNeg: Boolean, offsetHour: Int, offsetMinute: Int, offsetSecond: Int): ZoneOffset = {
23332333
var offsetTotal = offsetHour * 3600 + offsetMinute * 60 + offsetSecond
2334-
var q1 = offsetTotal * 37283 >>> 25 // divide a small positive int by 900
2334+
var qp = offsetTotal * 37283
23352335
if (offsetTotal > 64800) timezoneOffsetError() // 64800 == 18 * 60 * 60
2336-
if (q1 * 900 == offsetTotal) {
2337-
if (isNeg) q1 = -q1
2338-
var zoneOffset = zoneOffsets(q1 + 72)
2336+
if ((qp & 0x1FF8000) == 0) { // check if offsetTotal divisible by 900
2337+
qp >>>= 25 // divide offsetTotal by 900
2338+
if (isNeg) qp = -qp
2339+
var zoneOffset = zoneOffsets(qp + 72)
23392340
if (zoneOffset ne null) zoneOffset
23402341
else {
23412342
if (isNeg) offsetTotal = -offsetTotal
23422343
zoneOffset = ZoneOffset.ofTotalSeconds(offsetTotal)
2343-
zoneOffsets(q1 + 72) = zoneOffset
2344+
zoneOffsets(qp + 72) = zoneOffset
23442345
zoneOffset
23452346
}
23462347
} else {
@@ -2358,7 +2359,7 @@ final class JsonReader private[jsoniter_scala](
23582359
})
23592360

23602361
private[this] def dayOfYearForYearMonth(year: Int, month: Int): Int =
2361-
((month * 1050835331877L - 1036518774222L) >> 35).toInt - // (month * 367 - 362) / 12
2362+
((month * 1002277 - 988622) >> 15) - // (month * 367 - 362) / 12
23622363
(if (month <= 2) 0
23632364
else if (isLeap(year)) 1
23642365
else 2)

0 commit comments

Comments
 (0)