From f0a233bdc3efe48b0ea75afca5ef542acbbc8d8e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 7 Feb 2025 22:13:12 +0100 Subject: [PATCH] pkg/archive: avoid allocations with strings.Compare (mirror) pkg/archive/changes_linux.go:146:10: avoid allocations with strings.Compare (mirror) switch bytes.Compare([]byte(ni1.name), []byte(ni2.name)) { ^ Signed-off-by: Sebastiaan van Stijn --- pkg/archive/changes_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/archive/changes_linux.go b/pkg/archive/changes_linux.go index 6bb358486a..9a041b0984 100644 --- a/pkg/archive/changes_linux.go +++ b/pkg/archive/changes_linux.go @@ -1,11 +1,11 @@ package archive import ( - "bytes" "fmt" "os" "path/filepath" "sort" + "strings" "syscall" "unsafe" @@ -143,7 +143,7 @@ func (w *walker) walk(path string, i1, i2 os.FileInfo) (err error) { ni1 := names1[ix1] ni2 := names2[ix2] - switch bytes.Compare([]byte(ni1.name), []byte(ni2.name)) { + switch strings.Compare(ni1.name, ni2.name) { case -1: // ni1 < ni2 -- advance ni1 // we will not encounter ni1 in names2 names = append(names, ni1.name)