Small premature optimization in `isUUID()`.

If the length isn't `36`, return `false` immediately before firing up
the regexp engine.
This commit is contained in:
Sean Chittenden 2017-02-01 11:00:06 -08:00
parent df52e83720
commit e39dd09bfa
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
1 changed files with 5 additions and 0 deletions

View File

@ -14,6 +14,11 @@ var validUUID = regexp.MustCompile(`(?i)^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f
// isUUID returns true if the given string is a valid UUID.
func isUUID(str string) bool {
const uuidLen = 36
if len(str) != uuidLen {
return false
}
return validUUID.MatchString(str)
}