Skip to content

Commit f4bde68

Browse files
committed
replace some basic uses of fmt.Sprintf()
Really tiny gains here, and doesn't significantly impact readability: BenchmarkSprintf BenchmarkSprintf-10 11528700 91.59 ns/op 32 B/op 1 allocs/op BenchmarkConcat BenchmarkConcat-10 100000000 11.76 ns/op 0 B/op 0 allocs/op Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8aee745 commit f4bde68

8 files changed

Lines changed: 8 additions & 9 deletions

File tree

cli/command/config/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (c *configContext) Labels() string {
103103
}
104104
var joinLabels []string
105105
for k, v := range mapLabels {
106-
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
106+
joinLabels = append(joinLabels, k+"="+v)
107107
}
108108
return strings.Join(joinLabels, ",")
109109
}

cli/command/container/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio
9191
if v == nil {
9292
newEnv = append(newEnv, k)
9393
} else {
94-
newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v))
94+
newEnv = append(newEnv, k+"="+*v)
9595
}
9696
}
9797
copts.env = *opts.NewListOptsRef(&newEnv, nil)

cli/command/container/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
101101
if v == nil {
102102
newEnv = append(newEnv, k)
103103
} else {
104-
newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, *v))
104+
newEnv = append(newEnv, k+"="+*v)
105105
}
106106
}
107107
copts.env = *opts.NewListOptsRef(&newEnv, nil)

cli/command/formatter/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (c *ContainerContext) Labels() string {
247247

248248
var joinLabels []string
249249
for k, v := range c.c.Labels {
250-
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
250+
joinLabels = append(joinLabels, k+"="+v)
251251
}
252252
return strings.Join(joinLabels, ",")
253253
}

cli/command/network/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (c *networkContext) Labels() string {
103103

104104
var joinLabels []string
105105
for k, v := range c.n.Labels {
106-
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
106+
joinLabels = append(joinLabels, k+"="+v)
107107
}
108108
return strings.Join(joinLabels, ",")
109109
}

cli/command/secret/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (c *secretContext) Labels() string {
110110
}
111111
var joinLabels []string
112112
for k, v := range mapLabels {
113-
joinLabels = append(joinLabels, fmt.Sprintf("%s=%s", k, v))
113+
joinLabels = append(joinLabels, k+"="+v)
114114
}
115115
return strings.Join(joinLabels, ",")
116116
}

cli/command/system/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func prettyPrintEvent(out io.Writer, event eventtypes.Message) error {
133133
sort.Strings(keys)
134134
for _, k := range keys {
135135
v := event.Actor.Attributes[k]
136-
attrs = append(attrs, fmt.Sprintf("%s=%s", k, v))
136+
attrs = append(attrs, k+"="+v)
137137
}
138138
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
139139
}

cli/compose/convert/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package convert
22

33
import (
4-
"fmt"
54
"os"
65
"sort"
76
"strings"
@@ -605,7 +604,7 @@ func convertEnvironment(source map[string]*string) []string {
605604
case nil:
606605
output = append(output, name)
607606
default:
608-
output = append(output, fmt.Sprintf("%s=%s", name, *value))
607+
output = append(output, name+"="+*value)
609608
}
610609
}
611610

0 commit comments

Comments
 (0)