Skip to content

Commit 6f70927

Browse files
authored
fix(performance): reduce memory allocation in containsPath (#3730)
Signed-off-by: Yoav Alon <[email protected]>
1 parent 9a2c2ad commit 6f70927

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

syft/internal/fileresolver/path_skipper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ func containsPath(p1, p2 string) bool {
143143
if p1Clean == p2Clean {
144144
return true
145145
}
146-
return strings.HasPrefix(p1Clean, p2Clean+"/")
146+
if !strings.HasPrefix(p1Clean, p2Clean) {
147+
return false
148+
}
149+
// This is done to avoid allocation of a new string
150+
return len(p1Clean) > len(p2Clean) && p1Clean[len(p2Clean)] == '/'
147151
}
148152

149153
func simpleClean(p string) string {

0 commit comments

Comments
 (0)