perf(parse): cut allocations and validate UTF-8 in the scan

This commit is contained in:
2026-09-20 22:15:10 +02:00
parent adf189aa2c
commit b4d564c682
6 changed files with 427 additions and 117 deletions
+9
View File
@@ -41,6 +41,15 @@ func decodeDecimalInt(tok string) (any, error) {
if err := checkNoLeadingZero(digits); err != nil {
return nil, err
}
// An unsigned token parses in place; only a sign needs the concatenated
// copy, and concatenating an empty sign still allocated.
if sign == "" {
i, err := strconv.ParseInt(digits, 10, 64)
if err != nil {
return nil, fmt.Errorf("integer %q out of range", tok)
}
return i, nil
}
i, err := strconv.ParseInt(sign+digits, 10, 64)
if err != nil {
return nil, fmt.Errorf("integer %q out of range", tok)