Skip to content

Commit

Permalink
perf: avoid heap allocation in applier findPackage (#7883)
Browse files Browse the repository at this point in the history
Co-authored-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
jinroh and knqyf263 authored Dec 9, 2024
1 parent 2c41ac8 commit 9bd6ed7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/fanal/applier/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ type History struct {
}

func findPackage(e ftypes.Package, s []ftypes.Package) *ftypes.Package {
for _, a := range s {
for i := range s {
a := &s[i] // do not range by value to avoid heap allocations
if a.Name == e.Name && a.Version == e.Version && a.Release == e.Release {
return &a
return a
}
}
return nil
Expand Down

0 comments on commit 9bd6ed7

Please sign in to comment.