From 1ed385987942c3068c77d97c9c070c5923ad8c1b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 10 Apr 2025 11:46:47 +0200 Subject: [PATCH] cli-plugins/manager: use lazyregexp to compile regexes on first use Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/plugin.go | 4 ++-- internal/lazyregexp/lazyregexp.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cli-plugins/manager/plugin.go b/cli-plugins/manager/plugin.go index ec196df16f..fa846452b5 100644 --- a/cli-plugins/manager/plugin.go +++ b/cli-plugins/manager/plugin.go @@ -8,14 +8,14 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "strings" "github.com/docker/cli/cli-plugins/metadata" + "github.com/docker/cli/internal/lazyregexp" "github.com/spf13/cobra" ) -var pluginNameRe = regexp.MustCompile("^[a-z][a-z0-9]*$") +var pluginNameRe = lazyregexp.New("^[a-z][a-z0-9]*$") // Plugin represents a potential plugin with all it's metadata. type Plugin struct { diff --git a/internal/lazyregexp/lazyregexp.go b/internal/lazyregexp/lazyregexp.go index c616a0a05b..62e29c55d0 100644 --- a/internal/lazyregexp/lazyregexp.go +++ b/internal/lazyregexp/lazyregexp.go @@ -75,6 +75,10 @@ func (r *Regexp) ReplaceAllLiteralString(src, repl string) string { return r.re().ReplaceAllLiteralString(src, repl) } +func (r *Regexp) String() string { + return r.re().String() +} + func (r *Regexp) SubexpNames() []string { return r.re().SubexpNames() }