MCPcopy Index your code
hub / github.com/buger/jsonparser / parseInt

Function parseInt

bytes.go:9–48  ·  view source on GitHub ↗

About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON

(bytes []byte)

Source from the content-addressed store, hash-verified

7
8// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
9func parseInt(bytes []byte) (v int64, ok bool, overflow bool) {
10 if len(bytes) == 0 {
11 return 0, false, false
12 }
13
14 var neg bool = false
15 if bytes[0] == '-' {
16 neg = true
17 bytes = bytes[1:]
18 }
19
20 var n uint64 = 0
21 for _, c := range bytes {
22 if c < '0' || c > '9' {
23 return 0, false, false
24 }
25 if n > maxUint64/10 {
26 return 0, false, true
27 }
28 n *= 10
29 n1 := n + uint64(c-'0')
30 if n1 < n {
31 return 0, false, true
32 }
33 n = n1
34 }
35
36 if n > maxInt64 {
37 if neg && n == absMinInt64 {
38 return -absMinInt64, true, false
39 }
40 return 0, false, true
41 }
42
43 if neg {
44 return -int64(n), true, false
45 } else {
46 return int64(n), true, false
47 }
48}

Callers 3

TestBytesParseIntFunction · 0.85
BenchmarkParseIntFunction · 0.85
ParseIntFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestBytesParseIntFunction · 0.68
BenchmarkParseIntFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…