Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@ const maxUint64 = 1<<64 - 1

// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON
func parseInt(bytes []byte) (v int64, ok bool, overflow bool) {
if len(bytes) == 0 {
l := len(bytes)
if l == 0 {
return 0, false, false
}

var neg bool = false
i := 0
if bytes[0] == '-' {
neg = true
i = 1
}

if l-i < 19 {
for ; i < l; i++ {
d := bytes[i] - '0'
if d > 9 {
return 0, false, false
}
v = 10*v + int64(d)
}

if neg {
return -v, true, false
}
return v, true, false
}

if neg {
bytes = bytes[1:]
}

Expand Down