From 5602258a4cc8829f54e441104277b4ced9757ed2 Mon Sep 17 00:00:00 2001 From: Pierre Guilleminot Date: Tue, 15 Oct 2024 09:36:10 +0200 Subject: [PATCH] perf: avoid heap allocation in applier findPackage --- pkg/fanal/applier/docker.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/fanal/applier/docker.go b/pkg/fanal/applier/docker.go index 6d1967497ab9..c14c95538c65 100644 --- a/pkg/fanal/applier/docker.go +++ b/pkg/fanal/applier/docker.go @@ -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