perf(python): hoist name normalization regexp to package level (#4926)

Avoid recompiling the separator pattern on every normalize() call during cataloging.

Signed-off-by: Matías Insaurralde <matias@insaurral.de>
This commit is contained in:
Matias Insaurralde
2026-06-01 21:17:43 -04:00
committed by GitHub
parent cf2ce643c3
commit a4fb2c0396
+4 -3
View File
@@ -11,10 +11,11 @@ import (
"github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg"
) )
// https://packaging.python.org/en/latest/specifications/name-normalization/
var nameNormalizationPattern = regexp.MustCompile(`[-_.]+`)
func normalize(name string) string { func normalize(name string) string {
// https://packaging.python.org/en/latest/specifications/name-normalization/ normalized := nameNormalizationPattern.ReplaceAllString(name, "-")
re := regexp.MustCompile(`[-_.]+`)
normalized := re.ReplaceAllString(name, "-")
return strings.ToLower(normalized) return strings.ToLower(normalized)
} }