From 1684d29ee85afa6b04bdb4f5b27461f1a382cdea Mon Sep 17 00:00:00 2001 From: saquibsaifee Date: Tue, 1 Sep 2026 17:34:10 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20get=5Fcomponent=5Fby=5Fp?= =?UTF-8?q?url=20to=20use=20early=20exit=20generator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: saquibsaifee --- cyclonedx/model/bom.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cyclonedx/model/bom.py b/cyclonedx/model/bom.py index 7cb0081e..dec1d96a 100644 --- a/cyclonedx/model/bom.py +++ b/cyclonedx/model/bom.py @@ -708,9 +708,10 @@ def get_component_by_purl(self, purl: Optional['PackageURL']) -> Optional[Compon .. deprecated:: next """ if purl: - found = [x for x in self.components if x.purl == purl] - if len(found) == 1: - return found[0] + gen = (x for x in self.components if x.purl == purl) + first = next(gen, None) + if first and next(gen, None) is None: + return first return None