From 3495894b26ae61cf11da2669170ff9d1c655896b Mon Sep 17 00:00:00 2001 From: skarimo <40482491+skarimo@users.noreply.github.com> Date: Mon, 10 Oct 2022 15:59:58 -0400 Subject: [PATCH] helper/schema: Compile valid field name regex once (#1062) --- helper/schema/schema.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 5b398fd1604..4a3e146b60d 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -1093,9 +1093,10 @@ func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap return nil } +var validFieldNameRe = regexp.MustCompile("^[a-z0-9_]+$") + func isValidFieldName(name string) bool { - re := regexp.MustCompile("^[a-z0-9_]+$") - return re.MatchString(name) + return validFieldNameRe.MatchString(name) } // resourceDiffer is an interface that is used by the private diff functions.