Skip to content

Commit 9bd6ed7

Browse files
jinrohknqyf263
andauthored
perf: avoid heap allocation in applier findPackage (#7883)
Co-authored-by: knqyf263 <[email protected]>
1 parent 2c41ac8 commit 9bd6ed7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/fanal/applier/docker.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ type History struct {
3131
}
3232

3333
func findPackage(e ftypes.Package, s []ftypes.Package) *ftypes.Package {
34-
for _, a := range s {
34+
for i := range s {
35+
a := &s[i] // do not range by value to avoid heap allocations
3536
if a.Name == e.Name && a.Version == e.Version && a.Release == e.Release {
36-
return &a
37+
return a
3738
}
3839
}
3940
return nil

0 commit comments

Comments
 (0)