mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 07:26:34 +01:00
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:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user