From a4fb2c03967e08120ff5b0d3f96bd6dc96ce15b2 Mon Sep 17 00:00:00 2001 From: Matias Insaurralde Date: Tue, 2 Jun 2026 03:17:43 +0200 Subject: [PATCH] perf(python): hoist name normalization regexp to package level (#4926) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid recompiling the separator pattern on every normalize() call during cataloging. Signed-off-by: Matías Insaurralde --- syft/pkg/cataloger/python/package.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/syft/pkg/cataloger/python/package.go b/syft/pkg/cataloger/python/package.go index 2932d9d4e..098088f13 100644 --- a/syft/pkg/cataloger/python/package.go +++ b/syft/pkg/cataloger/python/package.go @@ -11,10 +11,11 @@ import ( "github.com/anchore/syft/syft/pkg" ) +// https://packaging.python.org/en/latest/specifications/name-normalization/ +var nameNormalizationPattern = regexp.MustCompile(`[-_.]+`) + func normalize(name string) string { - // https://packaging.python.org/en/latest/specifications/name-normalization/ - re := regexp.MustCompile(`[-_.]+`) - normalized := re.ReplaceAllString(name, "-") + normalized := nameNormalizationPattern.ReplaceAllString(name, "-") return strings.ToLower(normalized) }