diff options
| author | bogem <[email protected]> | 2016-09-10 12:08:47 +0500 |
|---|---|---|
| committer | bogem <[email protected]> | 2016-09-10 12:08:47 +0500 |
| commit | d16d05ecad8d146ef127c975e2e3e167b6e38ad6 (patch) | |
| tree | a13921d2f956128ed2d1c123d89749db36625645 /uint32.go | |
| parent | 6fd2ff4ff8dfcdf5556fbdc0ac0284408274b1a7 (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.go | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -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 { |
