Move regex compilation to outside var for optimization

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
Riyaz Faizullabhoy 2016-01-06 16:21:30 -08:00
parent aff9eb929a
commit a64ffd4ae9
1 changed files with 3 additions and 1 deletions

View File

@ -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