@@ -1745,7 +1745,7 @@ final class JsonReader private[jsoniter_scala](
1745
1745
}
1746
1746
head = pos + 1
1747
1747
if (b1 == '-' && year == 0 || yearDigits == 10 && year > 1000000000 ) yearError(pos - 1 )
1748
- if (b != t) yearError(t, maxDigits, pos, b1 == '-' , yearDigits)
1748
+ if (b != t) yearError(t, maxDigits, pos, b1, yearDigits)
1749
1749
if (b1 == '-' ) year = - year
1750
1750
if (year >= 0 && year < 10000 ) digitError(pos)
1751
1751
year
@@ -2883,12 +2883,12 @@ final class JsonReader private[jsoniter_scala](
2883
2883
2884
2884
private [this ] def parseDuration (): Duration = {
2885
2885
var b = nextByte(head)
2886
- var s = 0
2886
+ var s = 0L
2887
2887
if (b == '-' ) {
2888
2888
b = nextByte(head)
2889
- s = - 1
2889
+ s = ~ s
2890
2890
}
2891
- if (b != 'P' ) durationOrPeriodStartError(s)
2891
+ if (b != 'P' ) durationOrPeriodStartError(s.toInt )
2892
2892
b = nextByte(head)
2893
2893
var state = - 1
2894
2894
if (b == 'T' ) {
@@ -2903,7 +2903,7 @@ final class JsonReader private[jsoniter_scala](
2903
2903
b = nextByte(head)
2904
2904
sx = ~ sx
2905
2905
}
2906
- if (b < '0' || b > '9' ) durationOrPeriodDigitError(s, sx, state)
2906
+ if (b < '0' || b > '9' ) durationOrPeriodDigitError(s.toInt , sx.toInt , state)
2907
2907
var x = ('0' - b).toLong
2908
2908
var pos = head
2909
2909
var buf = this .buf
@@ -2921,67 +2921,63 @@ final class JsonReader private[jsoniter_scala](
2921
2921
}) durationError(pos)
2922
2922
pos += 1
2923
2923
}
2924
- if (sx == 0 ) {
2925
- if (x == - 9223372036854775808L ) durationError(pos)
2926
- x = - x
2927
- }
2928
2924
if (b == 'D' && state < 0 ) {
2929
- if (x < - 106751991167300L || x > 106751991167300L ) durationError(pos) // -106751991167300L == Long.MinValue / 86400
2930
- seconds = x * 86400
2925
+ if (x < - 106751991167300L ) durationError(pos) // -106751991167300L == Long.MinValue / 86400
2926
+ seconds = (sx - (x ^ sx)) * 86400
2931
2927
state = 0
2932
2928
} else if (b == 'H' && state <= 0 ) {
2933
- if (x < - 2562047788015215L || x > 2562047788015215L ) durationError(pos) // -2562047788015215L == Long.MinValue / 3600
2934
- seconds = sumSeconds(x * 3600 , seconds, pos)
2929
+ if (x < - 2562047788015215L ) durationError(pos) // -2562047788015215L == Long.MinValue / 3600
2930
+ seconds = sumSeconds((sx - (x ^ sx)) * 3600 , seconds, pos)
2935
2931
state = 1
2936
2932
} else if (b == 'M' && state <= 1 ) {
2937
- if (x < - 153722867280912930L || x > 153722867280912930L ) durationError(pos) // -153722867280912930L == Long.MinValue / 60
2938
- seconds = sumSeconds(x * 60 , seconds, pos)
2933
+ if (x < - 153722867280912930L ) durationError(pos) // -153722867280912930L == Long.MinValue / 60
2934
+ seconds = sumSeconds((sx - (x ^ sx)) * 60 , seconds, pos)
2939
2935
state = 2
2940
- } else if (b == '.' ) {
2941
- pos += 1
2942
- seconds = sumSeconds(x, seconds, pos)
2943
- var nanoDigitWeight = 100000000
2944
- var bs = 0
2945
- if (pos + 9 < tail && {
2946
- bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2947
- ((bs + 0x767676 | bs) & 0x808080 ) == 0
2948
- } && {
2949
- nano = ((bs * 2561 & 0xFF00FF ) * 6553601 >> 16 ) * 1000000
2950
- pos += 3
2951
- bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2952
- nanoDigitWeight = 100000
2953
- ((bs + 0x767676 | bs) & 0x808080 ) == 0
2954
- } && {
2955
- nano += ((bs * 2561 & 0xFF00FF ) * 6553601 >> 16 ) * 1000
2956
- pos += 3
2957
- bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2958
- nanoDigitWeight = 100
2959
- ((bs + 0x767676 | bs) & 0x808080 ) == 0
2960
- }) {
2961
- nano += (bs * 2561 & 0xFF00FF ) * 6553601 >> 16
2962
- pos += 3
2963
- b = (bs >> 24 ).toByte
2964
- nanoDigitWeight = 0
2965
- } else {
2966
- while ({
2967
- if (pos >= tail) {
2968
- pos = loadMoreOrError(pos)
2969
- buf = this .buf
2970
- }
2971
- b = buf(pos)
2972
- (b >= '0' && b <= '9' ) && nanoDigitWeight != 0
2936
+ } else if (b == 'S' || b == '.' ) {
2937
+ if ((x | sx) == - 9223372036854775808L ) durationError(pos)
2938
+ seconds = sumSeconds(sx - (x ^ sx), seconds, pos)
2939
+ state = 3
2940
+ if (b == '.' ) {
2941
+ pos += 1
2942
+ var nanoDigitWeight = 100000000
2943
+ var bs = 0
2944
+ if (pos + 9 < tail && {
2945
+ bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2946
+ ((bs + 0x767676 | bs) & 0x808080 ) == 0
2947
+ } && {
2948
+ nano = ((bs * 2561 & 0xFF00FF ) * 6553601 >> 16 ) * 1000000
2949
+ pos += 3
2950
+ bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2951
+ nanoDigitWeight = 100000
2952
+ ((bs + 0x767676 | bs) & 0x808080 ) == 0
2953
+ } && {
2954
+ nano += ((bs * 2561 & 0xFF00FF ) * 6553601 >> 16 ) * 1000
2955
+ pos += 3
2956
+ bs = ByteArrayAccess .getInt(buf, pos) - 0x303030
2957
+ nanoDigitWeight = 100
2958
+ ((bs + 0x767676 | bs) & 0x808080 ) == 0
2973
2959
}) {
2974
- nano += (b - '0' ) * nanoDigitWeight
2975
- nanoDigitWeight = (nanoDigitWeight * 429496730L >> 32 ).toInt // divide a small positive int by 10
2976
- pos += 1
2960
+ nano += (bs * 2561 & 0xFF00FF ) * 6553601 >> 16
2961
+ pos += 3
2962
+ b = (bs >> 24 ).toByte
2963
+ nanoDigitWeight = 0
2964
+ } else {
2965
+ while ({
2966
+ if (pos >= tail) {
2967
+ pos = loadMoreOrError(pos)
2968
+ buf = this .buf
2969
+ }
2970
+ b = buf(pos)
2971
+ (b >= '0' && b <= '9' ) && nanoDigitWeight != 0
2972
+ }) {
2973
+ nano += (b - '0' ) * nanoDigitWeight
2974
+ nanoDigitWeight = (nanoDigitWeight * 429496730L >> 32 ).toInt // divide a small positive int by 10
2975
+ pos += 1
2976
+ }
2977
2977
}
2978
+ if (b != 'S' ) nanoError(nanoDigitWeight, 'S' , pos)
2979
+ nano = ((nano ^ sx) - sx).toInt
2978
2980
}
2979
- if (b != 'S' ) nanoError(nanoDigitWeight, 'S' , pos)
2980
- nano = (nano ^ sx) - sx
2981
- state = 3
2982
- } else if (b == 'S' ) {
2983
- seconds = sumSeconds(x, seconds, pos)
2984
- state = 3
2985
2981
} else durationError(state, pos)
2986
2982
b = nextByte(pos + 1 )
2987
2983
b != '"'
@@ -3516,10 +3512,8 @@ final class JsonReader private[jsoniter_scala](
3516
3512
}) periodError(pos)
3517
3513
pos += 1
3518
3514
}
3519
- if (sx == 0 ) {
3520
- if (x == - 2147483648 ) periodError(pos)
3521
- x = - x
3522
- }
3515
+ x = sx - (x ^ sx)
3516
+ if ((sx | x) == - 2147483648 ) periodError(pos)
3523
3517
if (b == 'Y' && state <= 0 ) {
3524
3518
years = x
3525
3519
state = 1
@@ -3824,13 +3818,13 @@ final class JsonReader private[jsoniter_scala](
3824
3818
3825
3819
private [this ] def durationError (state : Int , pos : Int ): Nothing = decodeError(state match {
3826
3820
case - 1 => " expected 'D' or digit"
3827
- case 0 => " expected 'H' or 'M' or 'S or '.' or digit"
3828
- case 1 => " expected 'M' or 'S or '.' or digit"
3829
- case _ => " expected 'S or '.' or digit"
3821
+ case 0 => " expected 'H' or 'M' or 'S' or '.' or digit"
3822
+ case 1 => " expected 'M' or 'S' or '.' or digit"
3823
+ case _ => " expected 'S' or '.' or digit"
3830
3824
}, pos)
3831
3825
3832
- private [this ] def yearError (t : Byte , maxDigits : Int , pos : Int , isNeg : Boolean , yearDigits : Int ): Nothing = {
3833
- if (! isNeg && yearDigits == 4 ) digitError(pos)
3826
+ private [this ] def yearError (t : Byte , maxDigits : Int , pos : Int , b : Byte , yearDigits : Int ): Nothing = {
3827
+ if (b != '-' && yearDigits == 4 ) digitError(pos)
3834
3828
if (yearDigits == maxDigits) tokenError(t, pos)
3835
3829
tokenOrDigitError(t, pos)
3836
3830
}
0 commit comments