About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
(bytes []byte)
| 7 | |
| 8 | // About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON |
| 9 | func 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 | } |
no outgoing calls
searching dependent graphs…