From c758f7e71b297fda2ef80fb1621dc3352b4ed537 Mon Sep 17 00:00:00 2001 From: saquibsaifee Date: Tue, 1 Sep 2026 17:35:36 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20get=5Fall=5Fnested=5Fcom?= =?UTF-8?q?ponents=20with=20stack=20iteration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: saquibsaifee --- cyclonedx/model/component.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cyclonedx/model/component.py b/cyclonedx/model/component.py index bc7152ae..3f81a1c3 100644 --- a/cyclonedx/model/component.py +++ b/cyclonedx/model/component.py @@ -1689,8 +1689,12 @@ def get_all_nested_components(self, include_self: bool = False) -> set['Componen if include_self: components.add(self) - for c in self.components: - components.update(c.get_all_nested_components(include_self=True)) + stack = list(self.components) + while stack: + current = stack.pop() + if current not in components: + components.add(current) + stack.extend(current.components) return components