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:
parent
df52e83720
commit
e39dd09bfa
|
@ -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.
|
// isUUID returns true if the given string is a valid UUID.
|
||||||
func isUUID(str string) bool {
|
func isUUID(str string) bool {
|
||||||
|
const uuidLen = 36
|
||||||
|
if len(str) != uuidLen {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return validUUID.MatchString(str)
|
return validUUID.MatchString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue