Skip to content

Commit

Permalink
Small premature optimization in isUUID().
Browse files Browse the repository at this point in the history
If the length isn't `36`, return `false` immediately before firing up
the regexp engine.
  • Loading branch information
sean- committed Feb 1, 2017
1 parent 0a34925 commit c5e140c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions consul/state/prepared_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit c5e140c

Please sign in to comment.