fix(performance): reduce memory allocation in containsPath (#3730)

Signed-off-by: Yoav Alon <yoav@orca.security>
This commit is contained in:
Yoav Alon 2025-03-13 20:39:57 +02:00 committed by GitHub
parent 9a2c2ad401
commit 6f70927bcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {