From d69c4f21894b617ebe3139a7459d9708e5f45730 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Fri, 24 Apr 2026 10:14:28 +0200 Subject: [PATCH] perf(extgen): hoist const block regexes out of parser loop --- internal/extgen/constparser.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/extgen/constparser.go b/internal/extgen/constparser.go index 86f80337cf..fea8c8c9cb 100644 --- a/internal/extgen/constparser.go +++ b/internal/extgen/constparser.go @@ -12,6 +12,8 @@ import ( var constRegex = regexp.MustCompile(`//\s*export_php:const$`) var classConstRegex = regexp.MustCompile(`//\s*export_php:classconst\s+(\w+)$`) var constDeclRegex = regexp.MustCompile(`const\s+(\w+)\s*=\s*(.+)`) +var constBlockDeclRegex = regexp.MustCompile(`^(\w+)\s*=\s*(.+)$`) +var constNameRegex = regexp.MustCompile(`^(\w+)$`) type ConstantParser struct{} @@ -109,7 +111,6 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e expectConstDecl = false expectClassConstDecl = false } else if inConstBlock && (expectConstDecl || expectClassConstDecl || exportAllInBlock) { - constBlockDeclRegex := regexp.MustCompile(`^(\w+)\s*=\s*(.+)$`) if matches := constBlockDeclRegex.FindStringSubmatch(line); len(matches) == 3 { name := matches[1] value := strings.TrimSpace(matches[2]) @@ -139,7 +140,6 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e expectConstDecl = false expectClassConstDecl = false } else { - constNameRegex := regexp.MustCompile(`^(\w+)$`) if matches := constNameRegex.FindStringSubmatch(line); len(matches) == 2 { name := matches[1]