@@ -1292,28 +1292,27 @@ final class JsonWriter private[jsoniter_scala](
1292
1292
val epochDay =
1293
1293
(if (epochSecond >= 0 ) epochSecond
1294
1294
else epochSecond - 86399 ) / 86400 // 86400 == seconds per day
1295
+ val secsOfDay = (epochSecond - epochDay * 86400 ).toInt
1295
1296
var marchZeroDay = epochDay + 719468 // 719468 == 719528 - 60 == days 0000 to 1970 - days 1st Jan to 1st Mar
1296
1297
var adjustYear = 0
1297
1298
if (marchZeroDay < 0 ) { // adjust negative years to positive for calculation
1298
1299
val adjust400YearCycles = to400YearCycle(marchZeroDay + 1 ) - 1
1299
1300
adjustYear = adjust400YearCycles * 400
1300
1301
marchZeroDay -= adjust400YearCycles * 146097L
1301
1302
}
1302
- var yearEst = to400YearCycle(marchZeroDay * 400 + 591 )
1303
- var marchDayOfYear = toMarchDayOfYear(marchZeroDay, yearEst )
1304
- if (marchDayOfYear < 0 ) { // fix estimate
1305
- yearEst -= 1
1306
- marchDayOfYear = toMarchDayOfYear(marchZeroDay, yearEst )
1303
+ var year = to400YearCycle(marchZeroDay * 400 + 591 )
1304
+ var marchDayOfYear = toMarchDayOfYear(marchZeroDay, year )
1305
+ if (marchDayOfYear < 0 ) { // fix year estimate
1306
+ year -= 1
1307
+ marchDayOfYear = toMarchDayOfYear(marchZeroDay, year )
1307
1308
}
1308
- yearEst += adjustYear // reset any negative year
1309
- val marchMonth = ((marchDayOfYear * 17965876275L + 7186350510L ) >> 39 ).toInt // (marchDayOfYear * 5 + 2) / 153
1310
- val year = yearEst + (marchMonth * 3435973837L >> 35 ).toInt // yearEst + marchMonth / 10 (convert march-based values back to january-based)
1309
+ val marchMonth = (marchDayOfYear * 17135 + 6854 ) >> 19 // (marchDayOfYear * 5 + 2) / 153
1310
+ year += (marchMonth * 3277 >> 15 ) + adjustYear // year += marchMonth / 10 + adjustYear (reset any negative year and convert march-based values back to january-based)
1311
1311
val month = marchMonth +
1312
1312
(if (marchMonth < 10 ) 3
1313
1313
else - 9 )
1314
- val day = marchDayOfYear - ((marchMonth * 1051407994122L - 17179869183L ) >> 35 ).toInt // marchDayOfYear - (marchMonth * 306 + 5) / 10 + 1
1315
- val secsOfDay = (epochSecond - epochDay * 86400 ).toInt
1316
- val hour = (secsOfDay * 2443359173L >> 43 ).toInt // divide a positive int by 3600
1314
+ val day = marchDayOfYear - ((marchMonth * 1002762 - 16383 ) >> 15 ) // marchDayOfYear - (marchMonth * 306 + 5) / 10 + 1
1315
+ val hour = secsOfDay * 37283 >>> 27 // divide a small positive int by 3600
1317
1316
val secsOfHour = secsOfDay - hour * 3600
1318
1317
val minute = secsOfHour * 17477 >> 20 // divide a small positive int by 60
1319
1318
val second = secsOfHour - minute * 60
@@ -1331,9 +1330,9 @@ final class JsonWriter private[jsoniter_scala](
1331
1330
1332
1331
private [this ] def to400YearCycle (day : Long ): Int = (day / 146097 ).toInt // 146097 == number of days in a 400 year cycle
1333
1332
1334
- private [this ] def toMarchDayOfYear (marchZeroDay : Long , yearEst : Int ): Int = {
1335
- val centuryEst = yearEst / 100
1336
- (marchZeroDay - yearEst * 365L ).toInt - (yearEst >> 2 ) + centuryEst - (centuryEst >> 2 )
1333
+ private [this ] def toMarchDayOfYear (marchZeroDay : Long , year : Int ): Int = {
1334
+ val century = (year * 1374389535L >> 37 ).toInt // divide an int by 100 (the sign correction is not needed)
1335
+ (marchZeroDay - year * 365L ).toInt - (year >> 2 ) + century - (century >> 2 )
1337
1336
}
1338
1337
1339
1338
private [this ] def writeLocalDate (x : LocalDate ): Unit = count = {
@@ -1608,7 +1607,7 @@ final class JsonWriter private[jsoniter_scala](
1608
1607
buf(p) = '-'
1609
1608
- totalSeconds
1610
1609
}
1611
- val q1 = ( q0 * 2443359173L >> 43 ).toInt // divide a positive int by 3600
1610
+ val q1 = q0 * 37283 >>> 27 // divide a small positive int by 3600
1612
1611
val r1 = q0 - q1 * 3600
1613
1612
var pos = write2Digits(q1, p + 1 , buf, ds)
1614
1613
buf(pos) = ':'
0 commit comments