From 8f57e7d2ef82d39e2c914b799e98ed6243b9b1d0 Mon Sep 17 00:00:00 2001 From: unclejack Date: Wed, 13 May 2015 21:42:45 +0300 Subject: [PATCH 1/2] image: precompile regexp Signed-off-by: Cristian Staretu --- image/image.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/image/image.go b/image/image.go index e86ed2ff3f..4e37ebc42d 100644 --- a/image/image.go +++ b/image/image.go @@ -19,6 +19,8 @@ import ( // For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk const MaxImageDepth = 127 +var validHex = regexp.MustCompile(`^([a-f0-9]{64})$`) + type Image struct { ID string `json:"id"` Parent string `json:"parent,omitempty"` @@ -266,7 +268,6 @@ func NewImgJSON(src []byte) (*Image, error) { // Check wheather id is a valid image ID or not func ValidateID(id string) error { - validHex := regexp.MustCompile(`^([a-f0-9]{64})$`) if ok := validHex.MatchString(id); !ok { return fmt.Errorf("image ID '%s' is invalid", id) } From cb08c1173fae541742af3c8329e00904edef48df Mon Sep 17 00:00:00 2001 From: unclejack Date: Wed, 13 May 2015 21:48:48 +0300 Subject: [PATCH 2/2] pkg/stringid: precompile regexp Signed-off-by: Cristian Staretu --- pkg/stringid/stringid.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/stringid/stringid.go b/pkg/stringid/stringid.go index 3e6ff2a921..6a683b686a 100644 --- a/pkg/stringid/stringid.go +++ b/pkg/stringid/stringid.go @@ -10,9 +10,11 @@ import ( const shortLen = 12 +var validShortID = regexp.MustCompile("^[a-z0-9]{12}$") + // Determine if an arbitrary string *looks like* a short ID. 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.