From 6d2fd44bc4fe9e3426a192cc3b14dfe3b316a72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=9C=E6=AC=A2?= Date: Sun, 6 Apr 2025 20:18:37 +0800 Subject: [PATCH] strconv/atoi.go: use switch to handle leading '+' and '-' in Atoi Replace if-else with a switch statement to handle leading '+' and '-' characters. --- src/strconv/atoi.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/strconv/atoi.go b/src/strconv/atoi.go index 599ad9b895..83e931fe24 100644 --- a/src/strconv/atoi.go +++ b/src/strconv/atoi.go @@ -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.