1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pkg/stringid: precompile regexp

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
This commit is contained in:
unclejack 2015-05-13 21:48:48 +03:00
parent 8f57e7d2ef
commit cb08c1173f

View file

@ -10,9 +10,11 @@ import (
const shortLen = 12 const shortLen = 12
var validShortID = regexp.MustCompile("^[a-z0-9]{12}$")
// Determine if an arbitrary string *looks like* a short ID. // Determine if an arbitrary string *looks like* a short ID.
func IsShortID(id string) bool { func IsShortID(id string) bool {
return regexp.MustCompile("^[a-z0-9]{12}$").MatchString(id) return validShortID.MatchString(id)
} }
// TruncateID returns a shorthand version of a string identifier for convenience. // TruncateID returns a shorthand version of a string identifier for convenience.