Skip to content

Commit 391668f

Browse files
committed
golangci-lint: enable perfsprint linter
cli/compose/types/types.go:568:17: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) return []byte(fmt.Sprintf("%v", e.External)), nil ^ cli/command/formatter/buildcache.go:174:9: fmt.Sprintf can be replaced with faster strconv.Itoa (perfsprint) return fmt.Sprintf("%d", c.v.UsageCount) ^ cli/command/formatter/buildcache.go:178:9: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) return fmt.Sprintf("%t", c.v.InUse) ^ cli/command/formatter/buildcache.go:182:9: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) return fmt.Sprintf("%t", c.v.Shared) ^ cli/command/formatter/image.go:259:9: fmt.Sprintf can be replaced with faster strconv.FormatInt (perfsprint) return fmt.Sprintf("%d", c.i.Containers) ^ cli/command/formatter/tabwriter/tabwriter_test.go:698:9: fmt.Sprintf can be replaced with faster strconv.Itoa (perfsprint) b.Run(fmt.Sprintf("%d", x), func(b *testing.B) { ^ cli/command/formatter/tabwriter/tabwriter_test.go:720:9: fmt.Sprintf can be replaced with faster strconv.Itoa (perfsprint) b.Run(fmt.Sprintf("%d", h), func(b *testing.B) { ^ cli/command/image/prune.go:62:31: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) pruneFilters.Add("dangling", fmt.Sprintf("%v", !options.all)) ^ cli/command/network/formatter.go:92:9: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) return fmt.Sprintf("%v", c.n.EnableIPv6) ^ cli/command/network/formatter.go:96:9: fmt.Sprintf can be replaced with faster strconv.FormatBool (perfsprint) return fmt.Sprintf("%v", c.n.Internal) ^ cli/command/service/formatter.go:745:9: fmt.Sprintf can be replaced with faster strconv.FormatUint (perfsprint) pub = fmt.Sprintf("%d", pr.pStart) ^ cli/command/service/formatter.go:750:9: fmt.Sprintf can be replaced with faster strconv.FormatUint (perfsprint) tgt = fmt.Sprintf("%d", pr.tStart) ^ cli/command/service/opts.go:49:10: fmt.Sprintf can be replaced with faster strconv.FormatUint (perfsprint) return fmt.Sprintf("%v", *i.value) ^ cli/compose/loader/loader.go:720:36: fmt.Sprint can be replaced with faster strconv.Itoa (perfsprint) v, err := toServicePortConfigs(fmt.Sprint(value)) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8bbdb93 commit 391668f

10 files changed

Lines changed: 23 additions & 17 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- misspell
1717
- nakedret
1818
- nilerr # Detects code that returns nil even if it checks that the error is not nil.
19+
- perfsprint # Detects fmt.Sprintf uses that can be replaced with a faster alternative.
1920
- predeclared
2021
- revive
2122
- staticcheck

cli/command/formatter/buildcache.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package formatter
22

33
import (
4-
"fmt"
54
"sort"
5+
"strconv"
66
"strings"
77
"time"
88

@@ -171,13 +171,13 @@ func (c *buildCacheContext) LastUsedSince() string {
171171
}
172172

173173
func (c *buildCacheContext) UsageCount() string {
174-
return fmt.Sprintf("%d", c.v.UsageCount)
174+
return strconv.Itoa(c.v.UsageCount)
175175
}
176176

177177
func (c *buildCacheContext) InUse() string {
178-
return fmt.Sprintf("%t", c.v.InUse)
178+
return strconv.FormatBool(c.v.InUse)
179179
}
180180

181181
func (c *buildCacheContext) Shared() string {
182-
return fmt.Sprintf("%t", c.v.Shared)
182+
return strconv.FormatBool(c.v.Shared)
183183
}

cli/command/formatter/image.go

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

33
import (
4-
"fmt"
4+
"strconv"
55
"time"
66

77
"github.com/distribution/reference"
@@ -256,7 +256,7 @@ func (c *imageContext) Containers() string {
256256
if c.i.Containers == -1 {
257257
return "N/A"
258258
}
259-
return fmt.Sprintf("%d", c.i.Containers)
259+
return strconv.FormatInt(c.i.Containers, 10)
260260
}
261261

262262
// VirtualSize shows the virtual size of the image and all of its parent

cli/command/formatter/tabwriter/tabwriter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bytes"
99
"fmt"
1010
"io"
11+
"strconv"
1112
"testing"
1213
)
1314

@@ -695,7 +696,7 @@ func BenchmarkPyramid(b *testing.B) {
695696
for _, x := range [...]int{10, 100, 1000} {
696697
// Build a line with x cells.
697698
line := bytes.Repeat([]byte("a\t"), x)
698-
b.Run(fmt.Sprintf("%d", x), func(b *testing.B) {
699+
b.Run(strconv.Itoa(x), func(b *testing.B) {
699700
b.ReportAllocs()
700701
for i := 0; i < b.N; i++ {
701702
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
@@ -717,7 +718,7 @@ func BenchmarkRagged(b *testing.B) {
717718
lines[i] = bytes.Repeat([]byte("a\t"), w)
718719
}
719720
for _, h := range [...]int{10, 100, 1000} {
720-
b.Run(fmt.Sprintf("%d", h), func(b *testing.B) {
721+
b.Run(strconv.Itoa(h), func(b *testing.B) {
721722
b.ReportAllocs()
722723
for i := 0; i < b.N; i++ {
723724
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings

cli/command/image/prune.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package image
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67
"strings"
78

89
"github.com/docker/cli/cli"
@@ -59,7 +60,7 @@ Are you sure you want to continue?`
5960

6061
func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
6162
pruneFilters := options.filter.Value().Clone()
62-
pruneFilters.Add("dangling", fmt.Sprintf("%v", !options.all))
63+
pruneFilters.Add("dangling", strconv.FormatBool(!options.all))
6364
pruneFilters = command.PruneFilters(dockerCli, pruneFilters)
6465

6566
warning := danglingWarning

cli/command/network/formatter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package network
22

33
import (
4-
"fmt"
4+
"strconv"
55
"strings"
66

77
"github.com/docker/cli/cli/command/formatter"
@@ -89,11 +89,11 @@ func (c *networkContext) Scope() string {
8989
}
9090

9191
func (c *networkContext) IPv6() string {
92-
return fmt.Sprintf("%v", c.n.EnableIPv6)
92+
return strconv.FormatBool(c.n.EnableIPv6)
9393
}
9494

9595
func (c *networkContext) Internal() string {
96-
return fmt.Sprintf("%v", c.n.Internal)
96+
return strconv.FormatBool(c.n.Internal)
9797
}
9898

9999
func (c *networkContext) Labels() string {

cli/command/service/formatter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
44
"fmt"
55
"sort"
6+
"strconv"
67
"strings"
78
"time"
89

@@ -742,12 +743,12 @@ func (pr portRange) String() string {
742743
if pr.pEnd > pr.pStart {
743744
pub = fmt.Sprintf("%d-%d", pr.pStart, pr.pEnd)
744745
} else {
745-
pub = fmt.Sprintf("%d", pr.pStart)
746+
pub = strconv.FormatUint(uint64(pr.pStart), 10)
746747
}
747748
if pr.tEnd > pr.tStart {
748749
tgt = fmt.Sprintf("%d-%d", pr.tStart, pr.tEnd)
749750
} else {
750-
tgt = fmt.Sprintf("%d", pr.tStart)
751+
tgt = strconv.FormatUint(uint64(pr.tStart), 10)
751752
}
752753
return fmt.Sprintf("*:%s->%s/%s", pub, tgt, pr.protocol)
753754
}

cli/command/service/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (i *Uint64Opt) Type() string {
4646
// String returns a string repr of this option
4747
func (i *Uint64Opt) String() string {
4848
if i.value != nil {
49-
return fmt.Sprintf("%v", *i.value)
49+
return strconv.FormatUint(*i.value, 10)
5050
}
5151
return ""
5252
}

cli/compose/loader/loader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"path/filepath"
77
"reflect"
88
"sort"
9+
"strconv"
910
"strings"
1011
"time"
1112

@@ -717,7 +718,7 @@ var transformServicePort TransformerFunc = func(data interface{}) (interface{},
717718
for _, entry := range entries {
718719
switch value := entry.(type) {
719720
case int:
720-
v, err := toServicePortConfigs(fmt.Sprint(value))
721+
v, err := toServicePortConfigs(strconv.Itoa(value))
721722
if err != nil {
722723
return data, err
723724
}

cli/compose/types/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package types
33
import (
44
"encoding/json"
55
"fmt"
6+
"strconv"
67
"time"
78
)
89

@@ -565,7 +566,7 @@ func (e External) MarshalYAML() (interface{}, error) {
565566
// MarshalJSON makes External implement json.Marshaller
566567
func (e External) MarshalJSON() ([]byte, error) {
567568
if e.Name == "" {
568-
return []byte(fmt.Sprintf("%v", e.External)), nil
569+
return []byte(strconv.FormatBool(e.External)), nil
569570
}
570571
return []byte(fmt.Sprintf(`{"name": %q}`, e.Name)), nil
571572
}

0 commit comments

Comments
 (0)