Skip to content

Commit d1e33cb

Browse files
perf(extgen): hoist const block regexes out of parser loop (#2378)
1 parent 5c20828 commit d1e33cb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

internal/extgen/constparser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
var constRegex = regexp.MustCompile(`//\s*export_php:const$`)
1414
var classConstRegex = regexp.MustCompile(`//\s*export_php:classconst\s+(\w+)$`)
1515
var constDeclRegex = regexp.MustCompile(`const\s+(\w+)\s*=\s*(.+)`)
16+
var constBlockDeclRegex = regexp.MustCompile(`^(\w+)\s*=\s*(.+)$`)
17+
var constNameRegex = regexp.MustCompile(`^(\w+)$`)
1618

1719
type ConstantParser struct{}
1820

@@ -109,7 +111,6 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e
109111
expectConstDecl = false
110112
expectClassConstDecl = false
111113
} else if inConstBlock && (expectConstDecl || expectClassConstDecl || exportAllInBlock) {
112-
constBlockDeclRegex := regexp.MustCompile(`^(\w+)\s*=\s*(.+)$`)
113114
if matches := constBlockDeclRegex.FindStringSubmatch(line); len(matches) == 3 {
114115
name := matches[1]
115116
value := strings.TrimSpace(matches[2])
@@ -139,7 +140,6 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e
139140
expectConstDecl = false
140141
expectClassConstDecl = false
141142
} else {
142-
constNameRegex := regexp.MustCompile(`^(\w+)$`)
143143
if matches := constNameRegex.FindStringSubmatch(line); len(matches) == 2 {
144144
name := matches[1]
145145

0 commit comments

Comments
 (0)