From ff33808a79914b18db97ac00074ab515246bd29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 15 Dec 2025 17:56:10 +0100 Subject: [PATCH] modernize: Use strings.Cut instead of strings.Index where possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- .../remotecontext/internal/tarsum/versioning.go | 6 +++--- daemon/container/env.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/daemon/builder/remotecontext/internal/tarsum/versioning.go b/daemon/builder/remotecontext/internal/tarsum/versioning.go index 60aa170e7c..4494bfa7e6 100644 --- a/daemon/builder/remotecontext/internal/tarsum/versioning.go +++ b/daemon/builder/remotecontext/internal/tarsum/versioning.go @@ -34,11 +34,11 @@ func WriteV1Header(h *tar.Header, w io.Writer) { // the string or an empty string if no label separator is found. func VersionLabelForChecksum(checksum string) string { // Checksums are in the form: {versionLabel}+{hashID}:{hex} - sepIndex := strings.Index(checksum, "+") - if sepIndex < 0 { + before, _, ok := strings.Cut(checksum, "+") + if !ok { return "" } - return checksum[:sepIndex] + return before } // GetVersions gets a list of all known tarsum versions. diff --git a/daemon/container/env.go b/daemon/container/env.go index a9a72e305d..943503234d 100644 --- a/daemon/container/env.go +++ b/daemon/container/env.go @@ -9,14 +9,14 @@ import ( func ReplaceOrAppendEnvValues(defaults, overrides []string) []string { cache := make(map[string]int, len(defaults)) for i, e := range defaults { - index := strings.Index(e, "=") - cache[e[:index]] = i + before, _, _ := strings.Cut(e, "=") + cache[before] = i } for _, value := range overrides { // Values w/o = means they want this env to be removed/unset. - index := strings.Index(value, "=") - if index < 0 { + before, _, ok := strings.Cut(value, "=") + if !ok { // no "=" in value if i, exists := cache[value]; exists { defaults[i] = "" // Used to indicate it should be removed @@ -24,7 +24,7 @@ func ReplaceOrAppendEnvValues(defaults, overrides []string) []string { continue } - if i, exists := cache[value[:index]]; exists { + if i, exists := cache[before]; exists { defaults[i] = value } else { defaults = append(defaults, value)