aboutsummaryrefslogtreecommitdiff
path: root/src/flag
diff options
context:
space:
mode:
authorbogem <albertnigma@gmail.com>2016-09-09 23:23:32 +0500
committerIan Lance Taylor <iant@golang.org>2016-09-10 10:29:44 +0000
commite273a2794639692a216c46a0043e5e6929e0a959 (patch)
treee9521132327585c76581c30f6dca61784c19f6ea /src/flag
parent7b269195d30195f29080e17114aeec7821851870 (diff)
downloadgo-e273a2794639692a216c46a0043e5e6929e0a959.tar.gz
go-e273a2794639692a216c46a0043e5e6929e0a959.zip
flag: 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. Change-Id: I9e749179f66d5c50cafe98186641bcdbc546d2db Reviewed-on: https://go-review.googlesource.com/28914 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/flag')
-rw-r--r--src/flag/flag.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/flag/flag.go b/src/flag/flag.go
index e4705f2392..cb9f2837bf 100644
--- a/src/flag/flag.go
+++ b/src/flag/flag.go
@@ -94,7 +94,7 @@ func (b *boolValue) Set(s string) error {
func (b *boolValue) Get() interface{} { return bool(*b) }
-func (b *boolValue) String() string { return fmt.Sprintf("%v", *b) }
+func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) }
func (b *boolValue) IsBoolFlag() bool { return true }
@@ -121,7 +121,7 @@ func (i *intValue) Set(s string) error {
func (i *intValue) Get() interface{} { return int(*i) }
-func (i *intValue) String() string { return fmt.Sprintf("%v", *i) }
+func (i *intValue) String() string { return strconv.Itoa(int(*i)) }
// -- int64 Value
type int64Value int64
@@ -139,7 +139,7 @@ func (i *int64Value) Set(s string) error {
func (i *int64Value) Get() interface{} { return int64(*i) }
-func (i *int64Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) }
// -- uint Value
type uintValue uint
@@ -157,7 +157,7 @@ func (i *uintValue) Set(s string) error {
func (i *uintValue) Get() interface{} { return uint(*i) }
-func (i *uintValue) String() string { return fmt.Sprintf("%v", *i) }
+func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) }
// -- uint64 Value
type uint64Value uint64
@@ -175,7 +175,7 @@ func (i *uint64Value) Set(s string) error {
func (i *uint64Value) Get() interface{} { return uint64(*i) }
-func (i *uint64Value) String() string { return fmt.Sprintf("%v", *i) }
+func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) }
// -- string Value
type stringValue string
@@ -192,7 +192,7 @@ func (s *stringValue) Set(val string) error {
func (s *stringValue) Get() interface{} { return string(*s) }
-func (s *stringValue) String() string { return fmt.Sprintf("%s", *s) }
+func (s *stringValue) String() string { return string(*s) }
// -- float64 Value
type float64Value float64
@@ -210,7 +210,7 @@ func (f *float64Value) Set(s string) error {
func (f *float64Value) Get() interface{} { return float64(*f) }
-func (f *float64Value) String() string { return fmt.Sprintf("%v", *f) }
+func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) }
// -- time.Duration Value
type durationValue time.Duration