mirror of
https://github.com/anchore/syft.git
synced 2026-06-10 06:18:24 +02: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:
parent
cf2ce643c3
commit
a4fb2c0396
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user