removes/docker: replace some fmt.Sprintfs with strconv

Teeny-tiny optimizations:

    BenchmarkSprintf-10       37735996    32.31  ns/op  0 B/op  0 allocs/op
    BenchmarkItoa-10         591945836     2.031 ns/op  0 B/op  0 allocs/op
    BenchmarkFormatUint-10   593701444     2.014 ns/op  0 B/op  0 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-06-23 13:05:41 +02:00
parent d7bc8694be
commit 710d22366d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 5 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"strconv"
refDocker "github.com/containerd/containerd/reference/docker" refDocker "github.com/containerd/containerd/reference/docker"
) )
@ -37,7 +38,7 @@ func FuzzFetcher(data []byte) int {
s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-%d/%d", 0, dataLen-1, dataLen)) rw.Header().Set("content-range", fmt.Sprintf("bytes %d-%d/%d", 0, dataLen-1, dataLen))
rw.Header().Set("content-length", fmt.Sprintf("%d", dataLen)) rw.Header().Set("content-length", strconv.Itoa(dataLen))
rw.Write(data) rw.Write(data)
})) }))
defer s.Close() defer s.Close()

View File

@ -25,6 +25,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/url" "net/url"
"strconv"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -39,8 +40,8 @@ func TestFetcherOpen(t *testing.T) {
if start > 0 { if start > 0 {
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start)) rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
} }
rw.Header().Set("content-length", fmt.Sprintf("%d", len(content[start:]))) rw.Header().Set("content-length", strconv.Itoa(len(content[start:])))
rw.Write(content[start:]) _, _ = rw.Write(content[start:])
})) }))
defer s.Close() defer s.Close()