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. --- float32.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'float32.go') diff --git a/float32.go b/float32.go index 7683fae..a243f81 100644 --- a/float32.go +++ b/float32.go @@ -1,9 +1,6 @@ package pflag -import ( - "fmt" - "strconv" -) +import "strconv" // -- float32 Value type float32Value float32 @@ -23,7 +20,7 @@ func (f *float32Value) Type() string { return "float32" } -func (f *float32Value) String() string { return fmt.Sprintf("%v", *f) } +func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } func float32Conv(sval string) (interface{}, error) { v, err := strconv.ParseFloat(sval, 32) -- cgit v1.2.3