From a64ffd4ae98a538619b931faae5f09b8fc11b62c Mon Sep 17 00:00:00 2001 From: Riyaz Faizullabhoy Date: Wed, 6 Jan 2016 16:21:30 -0800 Subject: [PATCH] Move regex compilation to outside var for optimization Signed-off-by: Riyaz Faizullabhoy --- tuf/data/roles.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tuf/data/roles.go b/tuf/data/roles.go index 823105c4e5..f749032114 100644 --- a/tuf/data/roles.go +++ b/tuf/data/roles.go @@ -26,6 +26,9 @@ var ValidRoles = map[string]string{ CanonicalTimestampRole: CanonicalTimestampRole, } +// Regex for validating delegation names +var delegationRegexp = regexp.MustCompile("^[-a-z0-9_/]+$") + // ErrNoSuchRole indicates the roles doesn't exist type ErrNoSuchRole struct { Role string @@ -117,7 +120,6 @@ func ValidRole(name string) bool { func IsDelegation(role string) bool { targetsBase := ValidRoles[CanonicalTargetsRole] + "/" - delegationRegexp := regexp.MustCompile("^[-a-z0-9_/]+$") whitelistedChars := delegationRegexp.MatchString(role) // Limit size of full role string to 255 chars for db column size limit