Merge pull request #51914 from sergeylanzman/master

Automatic merge from submit-queue (batch tested with PRs 55392, 55491, 51914, 55831, 55836). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Move regexp.MustCompile to global variable

Move regexp.MustCompile to global variable.
regexp.MustCompile heavy function and can be run on init app
```release-note
NONE
```

Kubernetes-commit: 79c22745660733c822cff6970db8ceb0b58a0989
This commit is contained in:
Kubernetes Publisher
2017-11-17 00:18:22 -08:00
2 changed files with 707 additions and 705 deletions

1400
Godeps/Godeps.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -43,7 +43,11 @@ type Parser struct {
width int
}
var ErrSyntax = errors.New("invalid syntax")
var (
ErrSyntax = errors.New("invalid syntax")
dictKeyRex = regexp.MustCompile(`^'([^']*)'$`)
sliceOperatorRex = regexp.MustCompile(`^(-?[\d]*)(:-?[\d]*)?(:[\d]*)?$`)
)
// Parse parsed the given text and return a node Parser.
// If an error is encountered, parsing stops and an empty
@@ -283,8 +287,7 @@ Loop:
}
// dict key
reg := regexp.MustCompile(`^'([^']*)'$`)
value := reg.FindStringSubmatch(text)
value := dictKeyRex.FindStringSubmatch(text)
if value != nil {
parser, err := parseAction("arraydict", fmt.Sprintf(".%s", value[1]))
if err != nil {
@@ -297,8 +300,7 @@ Loop:
}
//slice operator
reg = regexp.MustCompile(`^(-?[\d]*)(:-?[\d]*)?(:[\d]*)?$`)
value = reg.FindStringSubmatch(text)
value = sliceOperatorRex.FindStringSubmatch(text)
if value == nil {
return fmt.Errorf("invalid array index %s", text)
}