Skip to content

Commit 0c9d2ef

Browse files
committed
strconv: use switch to handle '+' and '-' in readFloat and decimal.set
1 parent 6d2fd44 commit 0c9d2ef

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/strconv/atof.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func (b *decimal) set(s string) (ok bool) {
7777
if i >= len(s) {
7878
return
7979
}
80-
switch {
81-
case s[i] == '+':
80+
switch s[i] {
81+
case '+':
8282
i++
83-
case s[i] == '-':
84-
b.neg = true
83+
case '-':
8584
i++
85+
b.neg = true
8686
}
8787

8888
// digits
@@ -135,9 +135,10 @@ func (b *decimal) set(s string) (ok bool) {
135135
return
136136
}
137137
esign := 1
138-
if s[i] == '+' {
138+
switch s[i] {
139+
case '+':
139140
i++
140-
} else if s[i] == '-' {
141+
case '-':
141142
i++
142143
esign = -1
143144
}
@@ -176,12 +177,12 @@ func readFloat(s string) (mantissa uint64, exp int, neg, trunc, hex bool, i int,
176177
if i >= len(s) {
177178
return
178179
}
179-
switch {
180-
case s[i] == '+':
180+
switch s[i] {
181+
case '+':
181182
i++
182-
case s[i] == '-':
183-
neg = true
183+
case '-':
184184
i++
185+
neg = true
185186
}
186187

187188
// digits
@@ -268,9 +269,10 @@ loop:
268269
return
269270
}
270271
esign := 1
271-
if s[i] == '+' {
272+
switch s[i] {
273+
case '+':
272274
i++
273-
} else if s[i] == '-' {
275+
case '-':
274276
i++
275277
esign = -1
276278
}

0 commit comments

Comments
 (0)