perf(parse): cut allocations and validate UTF-8 in the scan
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user