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:
Sebastiaan van Stijn
2023-06-23 13:05:24 +02:00
parent 738c153573
commit d7bc8694be
5 changed files with 20 additions and 22 deletions

View File

@@ -99,7 +99,7 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
s.Name, // 0
s.Namespace, // 1
s.Uid, // 2
fmt.Sprintf("%d", s.Attempt), // 3
strconv.Itoa(int(s.Attempt)), // 3
}, nameDelimiter)
}
@@ -108,11 +108,11 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
// unique.
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
return strings.Join([]string{
c.Name, // 0: container name
s.Name, // 1: pod name
s.Namespace, // 2: pod namespace
s.Uid, // 3: pod uid
fmt.Sprintf("%d", c.Attempt), // 4: attempt number of creating the container
c.Name, // 0: container name
s.Name, // 1: pod name
s.Namespace, // 2: pod namespace
s.Uid, // 3: pod uid
strconv.FormatUint(uint64(s.Attempt), 10), // 4: attempt number of creating the container
}, nameDelimiter)
}