From 28755b9e781bc82ca58d30267ae505a5db7ecc72 Mon Sep 17 00:00:00 2001 From: trevorprater Date: Fri, 3 Jul 2026 00:55:20 -0400 Subject: [PATCH] Improve parseInt short number path --- bytes.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bytes.go b/bytes.go index f5414b6f..da97fb24 100644 --- a/bytes.go +++ b/bytes.go @@ -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:] }