@@ -2206,10 +2206,10 @@ final class JsonWriter private[jsoniter_scala](
2206
2206
}
2207
2207
2208
2208
private [this ] def write18Digits (x : Long , pos : Int , buf : Array [Byte ], ds : Array [Short ]): Int = {
2209
- val q1 = x / 100000000
2210
- write8Digits((x - q1 * 100000000 ).toInt, {
2211
- val q2 = (q1 >>> 8 ) * 1441151881 >>> 49 // divide a small positive long by 100000000
2212
- write8Digits((q1 - q2 * 100000000 ).toInt, write2Digits(q2.toInt, pos, buf, ds), buf, ds)
2209
+ val q1 = ((x >>> 8 ) * 2.56e-6 ).toLong
2210
+ write8Digits((x - q1 * 100000000L ).toInt, {
2211
+ val q2 = (q1 >>> 8 ) * 1441151881L >>> 49 // divide a small positive long by 100000000
2212
+ write8Digits((q1 - q2 * 100000000L ).toInt, write2Digits(q2.toInt, pos, buf, ds), buf, ds)
2213
2213
}, buf, ds)
2214
2214
}
2215
2215
@@ -2280,11 +2280,29 @@ final class JsonWriter private[jsoniter_scala](
2280
2280
}
2281
2281
var q = q0.toInt
2282
2282
var lastPos = pos
2283
+ var posCorr = 0
2283
2284
if (q0 == q) {
2284
2285
lastPos += digitCount(q)
2285
2286
pos = lastPos
2286
2287
} else {
2287
- val q1 = q0 / 100000000
2288
+ if (q0 >= 1000000000000000000L ) {
2289
+ var z = q0
2290
+ q0 = (q0 >>> 1 ) + (q0 >>> 2 ) // Based upon the divu10() code from Hacker's Delight 2nd Edition by Henry Warren
2291
+ q0 += q0 >>> 4
2292
+ q0 += q0 >>> 8
2293
+ q0 += q0 >>> 16
2294
+ q0 += q0 >>> 32
2295
+ z -= q0 & 0xFFFFFFFFFFFFFFF8L
2296
+ q0 >>>= 3
2297
+ var r = (z - (q0 << 1 )).toInt
2298
+ if (r >= 10 ) {
2299
+ q0 += 1
2300
+ r -= 10
2301
+ }
2302
+ buf(pos + 18 ) = (r + '0' ).toByte
2303
+ posCorr = 1
2304
+ }
2305
+ val q1 = ((q0 >>> 8 ) * 2.56e-6 ).toLong // divide a positive long by 100000000
2288
2306
q = q1.toInt
2289
2307
if (q1 == q) {
2290
2308
lastPos += digitCount(q)
@@ -2298,7 +2316,7 @@ final class JsonWriter private[jsoniter_scala](
2298
2316
pos = write8Digits((q0 - q1 * 100000000 ).toInt, pos, buf, ds)
2299
2317
}
2300
2318
writePositiveIntDigits(q, lastPos, buf, ds)
2301
- pos
2319
+ pos + posCorr
2302
2320
}
2303
2321
2304
2322
// Based on the amazing work of Raffaello Giulietti
0 commit comments