mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 10:36:45 +01:00
fix(performance): reduce memory allocation in containsPath (#3730)
Signed-off-by: Yoav Alon <yoav@orca.security>
This commit is contained in:
parent
9a2c2ad401
commit
6f70927bcc
@ -143,7 +143,11 @@ func containsPath(p1, p2 string) bool {
|
||||
if p1Clean == p2Clean {
|
||||
return true
|
||||
}
|
||||
return strings.HasPrefix(p1Clean, p2Clean+"/")
|
||||
if !strings.HasPrefix(p1Clean, p2Clean) {
|
||||
return false
|
||||
}
|
||||
// This is done to avoid allocation of a new string
|
||||
return len(p1Clean) > len(p2Clean) && p1Clean[len(p2Clean)] == '/'
|
||||
}
|
||||
|
||||
func simpleClean(p string) string {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user