pkg/cri: 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:
parent
738c153573
commit
d7bc8694be
@ -17,7 +17,7 @@
|
|||||||
package sbserver
|
package sbserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
@ -39,9 +39,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
|||||||
case "windows":
|
case "windows":
|
||||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||||
if rootfsSize != 0 {
|
if rootfsSize != 0 {
|
||||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"containerd.io/snapshot/windows/rootfs.sizebytes": sizeStr,
|
"containerd.io/snapshot/windows/rootfs.sizebytes": strconv.FormatInt(rootfsSize, 10),
|
||||||
}
|
}
|
||||||
opts = append(opts, snapshots.WithLabels(labels))
|
opts = append(opts, snapshots.WithLabels(labels))
|
||||||
}
|
}
|
||||||
|
@ -135,10 +135,10 @@ func (c *criService) getSandboxDevShm(id string) string {
|
|||||||
// generated is unique as long as sandbox metadata is unique.
|
// generated is unique as long as sandbox metadata is unique.
|
||||||
func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
s.Name, // 0
|
s.Name, // 0
|
||||||
s.Namespace, // 1
|
s.Namespace, // 1
|
||||||
s.Uid, // 2
|
s.Uid, // 2
|
||||||
fmt.Sprintf("%d", s.Attempt), // 3
|
strconv.FormatUint(uint64(s.Attempt), 10), // 3
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +147,11 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
// unique.
|
// unique.
|
||||||
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
c.Name, // 0: container name
|
c.Name, // 0: container name
|
||||||
s.Name, // 1: pod name
|
s.Name, // 1: pod name
|
||||||
s.Namespace, // 2: pod namespace
|
s.Namespace, // 2: pod namespace
|
||||||
s.Uid, // 3: pod uid
|
s.Uid, // 3: pod uid
|
||||||
fmt.Sprintf("%d", c.Attempt), // 4: attempt number of creating the container
|
strconv.FormatUint(uint64(s.Attempt), 10), // 4: attempt number of creating the container
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
@ -147,9 +146,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
|||||||
case "windows":
|
case "windows":
|
||||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||||
if rootfsSize != 0 {
|
if rootfsSize != 0 {
|
||||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"containerd.io/snapshot/windows/rootfs.sizebytes": sizeStr,
|
"containerd.io/snapshot/windows/rootfs.sizebytes": strconv.FormatInt(rootfsSize, 10),
|
||||||
}
|
}
|
||||||
opts = append(opts, snapshots.WithLabels(labels))
|
opts = append(opts, snapshots.WithLabels(labels))
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
s.Name, // 0
|
s.Name, // 0
|
||||||
s.Namespace, // 1
|
s.Namespace, // 1
|
||||||
s.Uid, // 2
|
s.Uid, // 2
|
||||||
fmt.Sprintf("%d", s.Attempt), // 3
|
strconv.Itoa(int(s.Attempt)), // 3
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,11 +108,11 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
// unique.
|
// unique.
|
||||||
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
c.Name, // 0: container name
|
c.Name, // 0: container name
|
||||||
s.Name, // 1: pod name
|
s.Name, // 1: pod name
|
||||||
s.Namespace, // 2: pod namespace
|
s.Namespace, // 2: pod namespace
|
||||||
s.Uid, // 3: pod uid
|
s.Uid, // 3: pod uid
|
||||||
fmt.Sprintf("%d", c.Attempt), // 4: attempt number of creating the container
|
strconv.FormatUint(uint64(s.Attempt), 10), // 4: attempt number of creating the container
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -76,7 +77,7 @@ func ServeExec(w http.ResponseWriter, req *http.Request, executor Executor, podN
|
|||||||
Causes: []metav1.StatusCause{
|
Causes: []metav1.StatusCause{
|
||||||
{
|
{
|
||||||
Type: remotecommandconsts.ExitCodeCauseType,
|
Type: remotecommandconsts.ExitCodeCauseType,
|
||||||
Message: fmt.Sprintf("%d", rc),
|
Message: strconv.Itoa(rc),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user