aboutsummaryrefslogtreecommitdiff
path: root/uint32.go
diff options
context:
space:
mode:
authorbogem <[email protected]>2016-09-10 12:08:47 +0500
committerbogem <[email protected]>2016-09-10 12:08:47 +0500
commitd16d05ecad8d146ef127c975e2e3e167b6e38ad6 (patch)
treea13921d2f956128ed2d1c123d89749db36625645 /uint32.go
parent6fd2ff4ff8dfcdf5556fbdc0ac0284408274b1a7 (diff)
Use strconv instead of fmt in values' String funcs
The existing implementation of flag values with fmt package uses more memory and works slower than the implementation with strconv package.
Diffstat (limited to 'uint32.go')
-rw-r--r--uint32.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/uint32.go b/uint32.go
index 294fcaa..d802453 100644
--- a/uint32.go
+++ b/uint32.go
@@ -1,18 +1,15 @@
package pflag
-import (
- "fmt"
- "strconv"
-)
+import "strconv"
-// -- uint16 value
+// -- uint32 value
type uint32Value uint32
func newUint32Value(val uint32, p *uint32) *uint32Value {
*p = val
return (*uint32Value)(p)
}
-func (i *uint32Value) String() string { return fmt.Sprintf("%d", *i) }
+
func (i *uint32Value) Set(s string) error {
v, err := strconv.ParseUint(s, 0, 32)
*i = uint32Value(v)
@@ -23,6 +20,8 @@ func (i *uint32Value) Type() string {
return "uint32"
}
+func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
+
func uint32Conv(sval string) (interface{}, error) {
v, err := strconv.ParseUint(sval, 0, 32)
if err != nil {