From d16d05ecad8d146ef127c975e2e3e167b6e38ad6 Mon Sep 17 00:00:00 2001 From: bogem Date: Sat, 10 Sep 2016 12:08:47 +0500 Subject: 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. --- uint32.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'uint32.go') 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 { -- cgit v1.2.3