strconv/atoi.go: use switch to handle leading '+' and '-' in Atoi

Replace if-else with a switch statement to handle leading '+' and '-'
characters.
This commit is contained in:
喜欢 2025-04-06 20:18:37 +08:00 committed by GitHub
parent 1647896aa2
commit 6d2fd44bc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -204,11 +204,12 @@ func ParseInt(s string, base int, bitSize int) (i int64, err error) {
// Pick off leading sign.
s0 := s
neg := false
if s[0] == '+' {
switch s[0] {
case '+':
s = s[1:]
case '-':
s = s[1:]
} else if s[0] == '-' {
neg = true
s = s[1:]
}
// Convert unsigned and check range.