Skip to content

Commit

Permalink
Merge pull request #1786 from austinvazquez/optimize-itoa
Browse files Browse the repository at this point in the history
Replace fmt.Sprintf's with strconv.Format's
  • Loading branch information
dearchap authored Jun 26, 2023
2 parents dafd175 + 4148aa8 commit 4a9488f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
3 changes: 1 addition & 2 deletions flag_bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"errors"
"fmt"
"strconv"
)

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

// ToString formats the bool value
func (i boolValue) ToString(b bool) string {
return fmt.Sprintf("%v", b)
return strconv.FormatBool(b)
}

// Below functions are to satisfy the flag.Value interface
Expand Down
3 changes: 1 addition & 2 deletions flag_float.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"fmt"
"strconv"
)

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

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

// Below functions are to satisfy the flag.Value interface
Expand Down
3 changes: 1 addition & 2 deletions flag_int.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"fmt"
"strconv"
)

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

func (i intValue) ToString(b int64) string {
return fmt.Sprintf("%d", b)
return strconv.FormatInt(b, 10)
}

// Below functions are to satisfy the flag.Value interface
Expand Down
3 changes: 1 addition & 2 deletions flag_uint.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
"fmt"
"strconv"
)

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

func (i uintValue) ToString(b uint64) string {
return fmt.Sprintf("%d", b)
return strconv.FormatUint(b, 10)
}

// Below functions are to satisfy the flag.Value interface
Expand Down

0 comments on commit 4a9488f

Please sign in to comment.