|
|
@@ -113,13 +113,9 @@ func (iter *Iterator) ReadUint32() (ret uint32) {
|
|
|
}
|
|
|
|
|
|
func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
- defer func() {
|
|
|
- if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' {
|
|
|
- iter.ReportError("readUint32", "can not decode float as int")
|
|
|
- }
|
|
|
- }()
|
|
|
ind := intDigits[c]
|
|
|
if ind == 0 {
|
|
|
+ iter.assertInteger()
|
|
|
return 0 // single zero
|
|
|
}
|
|
|
if ind == invalidCharForNumber {
|
|
|
@@ -132,12 +128,14 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
ind2 := intDigits[iter.buf[i]]
|
|
|
if ind2 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
i++
|
|
|
ind3 := intDigits[iter.buf[i]]
|
|
|
if ind3 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*10 + uint32(ind2)
|
|
|
}
|
|
|
//iter.head = i + 1
|
|
|
@@ -146,30 +144,35 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
ind4 := intDigits[iter.buf[i]]
|
|
|
if ind4 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*100 + uint32(ind2)*10 + uint32(ind3)
|
|
|
}
|
|
|
i++
|
|
|
ind5 := intDigits[iter.buf[i]]
|
|
|
if ind5 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*1000 + uint32(ind2)*100 + uint32(ind3)*10 + uint32(ind4)
|
|
|
}
|
|
|
i++
|
|
|
ind6 := intDigits[iter.buf[i]]
|
|
|
if ind6 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*10000 + uint32(ind2)*1000 + uint32(ind3)*100 + uint32(ind4)*10 + uint32(ind5)
|
|
|
}
|
|
|
i++
|
|
|
ind7 := intDigits[iter.buf[i]]
|
|
|
if ind7 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*100000 + uint32(ind2)*10000 + uint32(ind3)*1000 + uint32(ind4)*100 + uint32(ind5)*10 + uint32(ind6)
|
|
|
}
|
|
|
i++
|
|
|
ind8 := intDigits[iter.buf[i]]
|
|
|
if ind8 == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value*1000000 + uint32(ind2)*100000 + uint32(ind3)*10000 + uint32(ind4)*1000 + uint32(ind5)*100 + uint32(ind6)*10 + uint32(ind7)
|
|
|
}
|
|
|
i++
|
|
|
@@ -177,6 +180,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
value = value*10000000 + uint32(ind2)*1000000 + uint32(ind3)*100000 + uint32(ind4)*10000 + uint32(ind5)*1000 + uint32(ind6)*100 + uint32(ind7)*10 + uint32(ind8)
|
|
|
iter.head = i
|
|
|
if ind9 == invalidCharForNumber {
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
}
|
|
|
@@ -185,6 +189,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
ind = intDigits[iter.buf[i]]
|
|
|
if ind == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
if value > uint32SafeToMultiply10 {
|
|
|
@@ -199,6 +204,7 @@ func (iter *Iterator) readUint32(c byte) (ret uint32) {
|
|
|
value = (value << 3) + (value << 1) + uint32(ind)
|
|
|
}
|
|
|
if !iter.loadMore() {
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
}
|
|
|
@@ -229,13 +235,9 @@ func (iter *Iterator) ReadUint64() uint64 {
|
|
|
}
|
|
|
|
|
|
func (iter *Iterator) readUint64(c byte) (ret uint64) {
|
|
|
- defer func() {
|
|
|
- if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' {
|
|
|
- iter.ReportError("readUint64", "can not decode float as int")
|
|
|
- }
|
|
|
- }()
|
|
|
ind := intDigits[c]
|
|
|
if ind == 0 {
|
|
|
+ iter.assertInteger()
|
|
|
return 0 // single zero
|
|
|
}
|
|
|
if ind == invalidCharForNumber {
|
|
|
@@ -243,11 +245,73 @@ func (iter *Iterator) readUint64(c byte) (ret uint64) {
|
|
|
return
|
|
|
}
|
|
|
value := uint64(ind)
|
|
|
+ if iter.tail-iter.head > 10 {
|
|
|
+ i := iter.head
|
|
|
+ ind2 := intDigits[iter.buf[i]]
|
|
|
+ if ind2 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind3 := intDigits[iter.buf[i]]
|
|
|
+ if ind3 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*10 + uint64(ind2)
|
|
|
+ }
|
|
|
+ //iter.head = i + 1
|
|
|
+ //value = value * 100 + uint32(ind2) * 10 + uint32(ind3)
|
|
|
+ i++
|
|
|
+ ind4 := intDigits[iter.buf[i]]
|
|
|
+ if ind4 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*100 + uint64(ind2)*10 + uint64(ind3)
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind5 := intDigits[iter.buf[i]]
|
|
|
+ if ind5 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*1000 + uint64(ind2)*100 + uint64(ind3)*10 + uint64(ind4)
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind6 := intDigits[iter.buf[i]]
|
|
|
+ if ind6 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*10000 + uint64(ind2)*1000 + uint64(ind3)*100 + uint64(ind4)*10 + uint64(ind5)
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind7 := intDigits[iter.buf[i]]
|
|
|
+ if ind7 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*100000 + uint64(ind2)*10000 + uint64(ind3)*1000 + uint64(ind4)*100 + uint64(ind5)*10 + uint64(ind6)
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind8 := intDigits[iter.buf[i]]
|
|
|
+ if ind8 == invalidCharForNumber {
|
|
|
+ iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
+ return value*1000000 + uint64(ind2)*100000 + uint64(ind3)*10000 + uint64(ind4)*1000 + uint64(ind5)*100 + uint64(ind6)*10 + uint64(ind7)
|
|
|
+ }
|
|
|
+ i++
|
|
|
+ ind9 := intDigits[iter.buf[i]]
|
|
|
+ value = value*10000000 + uint64(ind2)*1000000 + uint64(ind3)*100000 + uint64(ind4)*10000 + uint64(ind5)*1000 + uint64(ind6)*100 + uint64(ind7)*10 + uint64(ind8)
|
|
|
+ iter.head = i
|
|
|
+ if ind9 == invalidCharForNumber {
|
|
|
+ iter.assertInteger()
|
|
|
+ return value
|
|
|
+ }
|
|
|
+ }
|
|
|
for {
|
|
|
for i := iter.head; i < iter.tail; i++ {
|
|
|
ind = intDigits[iter.buf[i]]
|
|
|
if ind == invalidCharForNumber {
|
|
|
iter.head = i
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
if value > uint64SafeToMultiple10 {
|
|
|
@@ -262,7 +326,14 @@ func (iter *Iterator) readUint64(c byte) (ret uint64) {
|
|
|
value = (value << 3) + (value << 1) + uint64(ind)
|
|
|
}
|
|
|
if !iter.loadMore() {
|
|
|
+ iter.assertInteger()
|
|
|
return value
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func (iter *Iterator) assertInteger() {
|
|
|
+ if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' {
|
|
|
+ iter.ReportError("assertInteger", "can not decode float as int")
|
|
|
+ }
|
|
|
+}
|