From 0e305d695820779a5c66fbe3434e3293911d7f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 17 Mar 2022 21:58:54 +0100 Subject: [PATCH] all: Use strings.Cut Updates #9687 --- config/env.go | 4 ++-- modules/config.go | 7 ++----- tpl/collections/apply.go | 9 ++++----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/config/env.go b/config/env.go index 1e7d4721655..1e9266b17ec 100644 --- a/config/env.go +++ b/config/env.go @@ -41,8 +41,8 @@ func SetEnvVars(oldVars *[]string, keyValues ...string) { } func SplitEnvVar(v string) (string, string) { - parts := strings.SplitN(v, "=", 2) - return parts[0], parts[1] + name, value, _ := strings.Cut(v, "=") + return name, value } func setEnvVar(vars *[]string, key, value string) { diff --git a/modules/config.go b/modules/config.go index ada39cc1f91..04bf1b42206 100644 --- a/modules/config.go +++ b/modules/config.go @@ -402,11 +402,8 @@ func (m Mount) Component() string { } func (m Mount) ComponentAndName() (string, string) { - k := strings.Index(m.Target, fileSeparator) - if k == -1 { - return m.Target, "" - } - return m.Target[:k], m.Target[k+1:] + c, n, _ := strings.Cut(m.Target, fileSeparator) + return c, n } func getStaticDirs(cfg config.Provider) []string { diff --git a/tpl/collections/apply.go b/tpl/collections/apply.go index 3b8de5f0e90..9fd5c2d0c9e 100644 --- a/tpl/collections/apply.go +++ b/tpl/collections/apply.go @@ -107,15 +107,14 @@ func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (re } func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) { - if !strings.ContainsRune(fname, '.') { + namespace, methodName, ok := strings.Cut(fname, ".") + if !ok { templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter) return templ.GetFunc(fname) } - ss := strings.SplitN(fname, ".", 2) - // Namespace - nv, found := ns.lookupFunc(ss[0]) + nv, found := ns.lookupFunc(namespace) if !found { return reflect.Value{}, false } @@ -131,7 +130,7 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) { nv = reflect.ValueOf(v) // method - m := hreflect.GetMethodByName(nv, ss[1]) + m := hreflect.GetMethodByName(nv, methodName) if m.Kind() == reflect.Invalid { return reflect.Value{}, false