From 8b27eee0f0229f5eb10bcfc83883279548160d0a Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Mon, 15 Sep 2014 23:30:10 -0400 Subject: [PATCH] Refactor all pre-compiled regexp to package level vars Addresses #8057 Docker-DCO-1.1-Signed-off-by: Phil Estes --- opts/opts.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/opts/opts.go b/opts/opts.go index 0ed0f62bcd..f57ef8b6d1 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -14,6 +14,11 @@ import ( "github.com/docker/docker/pkg/parsers" ) +var ( + alphaRegexp = regexp.MustCompile(`[a-zA-Z]`) + domainRegexp = regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) +) + func ListVar(values *[]string, names []string, usage string) { flag.Var(newListOptsRef(values, nil), names, usage) } @@ -184,12 +189,10 @@ func ValidateDnsSearch(val string) (string, error) { } func validateDomain(val string) (string, error) { - alpha := regexp.MustCompile(`[a-zA-Z]`) - if alpha.FindString(val) == "" { + if alphaRegexp.FindString(val) == "" { return "", fmt.Errorf("%s is not a valid domain", val) } - re := regexp.MustCompile(`^(:?(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9]))(:?\.(:?[a-zA-Z0-9]|(:?[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])))*)\.?\s*$`) - ns := re.FindSubmatch([]byte(val)) + ns := domainRegexp.FindSubmatch([]byte(val)) if len(ns) > 0 { return string(ns[1]), nil }