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-02 03:17:43 +02:00 committed by GitHub
parent cf2ce643c3
commit a4fb2c0396
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,10 +11,11 @@ import (
"github.com/anchore/syft/syft/pkg" "github.com/anchore/syft/syft/pkg"
) )
func normalize(name string) string {
// https://packaging.python.org/en/latest/specifications/name-normalization/ // https://packaging.python.org/en/latest/specifications/name-normalization/
re := regexp.MustCompile(`[-_.]+`) var nameNormalizationPattern = regexp.MustCompile(`[-_.]+`)
normalized := re.ReplaceAllString(name, "-")
func normalize(name string) string {
normalized := nameNormalizationPattern.ReplaceAllString(name, "-")
return strings.ToLower(normalized) return strings.ToLower(normalized)
} }