Skip to content

Commit 4a9488f

Browse files
authored
Merge pull request #1786 from austinvazquez/optimize-itoa
Replace fmt.Sprintf's with strconv.Format's
2 parents dafd175 + 4148aa8 commit 4a9488f

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

flag_bool.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cli
22

33
import (
44
"errors"
5-
"fmt"
65
"strconv"
76
)
87

@@ -48,7 +47,7 @@ func (i boolValue) Create(val bool, p *bool, c BoolConfig) Value {
4847

4948
// ToString formats the bool value
5049
func (i boolValue) ToString(b bool) string {
51-
return fmt.Sprintf("%v", b)
50+
return strconv.FormatBool(b)
5251
}
5352

5453
// Below functions are to satisfy the flag.Value interface

flag_float.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"fmt"
54
"strconv"
65
)
76

@@ -18,7 +17,7 @@ func (f floatValue) Create(val float64, p *float64, c NoConfig) Value {
1817
}
1918

2019
func (f floatValue) ToString(b float64) string {
21-
return fmt.Sprintf("%v", b)
20+
return strconv.FormatFloat(b, 'g', -1, 64)
2221
}
2322

2423
// Below functions are to satisfy the flag.Value interface

flag_int.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"fmt"
54
"strconv"
65
)
76

@@ -29,7 +28,7 @@ func (i intValue) Create(val int64, p *int64, c IntegerConfig) Value {
2928
}
3029

3130
func (i intValue) ToString(b int64) string {
32-
return fmt.Sprintf("%d", b)
31+
return strconv.FormatInt(b, 10)
3332
}
3433

3534
// Below functions are to satisfy the flag.Value interface

flag_uint.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"fmt"
54
"strconv"
65
)
76

@@ -24,7 +23,7 @@ func (i uintValue) Create(val uint64, p *uint64, c IntegerConfig) Value {
2423
}
2524

2625
func (i uintValue) ToString(b uint64) string {
27-
return fmt.Sprintf("%d", b)
26+
return strconv.FormatUint(b, 10)
2827
}
2928

3029
// Below functions are to satisfy the flag.Value interface

0 commit comments

Comments
 (0)