mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
modernize: Use strings.Cut instead of strings.Index where possible
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user