From 21ee998b88c5e064306e20da32cd2092c2f534f5 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 7 Jun 2026 12:38:01 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Restore=20O(1)=20hash=20map?= =?UTF-8?q?=20lookups=20in=20semantic=20registry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced generator comprehensions iterating over dictionaries with O(1) dictionary key lookups (`in` operator) in `_get_direct_connections_by_source` and `_get_positional_connections_by_source`. Also fixed a bug in `_get_direct_connections_by_source` where an implicit fall-through was causing double evaluation. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- src/codeweaver/semantic/registry.py | 31 ++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/codeweaver/semantic/registry.py b/src/codeweaver/semantic/registry.py index 37b77abe2..47bfe054e 100644 --- a/src/codeweaver/semantic/registry.py +++ b/src/codeweaver/semantic/registry.py @@ -344,17 +344,12 @@ def _get_direct_connections_by_source( """Get DirectConnections by their source Thing name across all languages.""" if language: yield from self.direct_connections[language].get(source, []) - yield from ( - next( - ( - conns - for content in self._direct_connections.values() - for con_name, conns in content.items() - if con_name == source - ), - [], - ) - ) + # Iterate over contents using direct key lookups to avoid O(N^2) generator overhead and preserve O(1) hash map access + else: + for content in self._direct_connections.values(): + if source in content: + yield from content[source] + break def _get_positional_connections_by_source( self, source: ThingNameT, *, language: SemanticSearchLanguage | None = None @@ -362,15 +357,11 @@ def _get_positional_connections_by_source( """Get PositionalConnectionss by their source Thing name across all languages.""" if language: return self.positional_connections[language].get(source) - return next( - ( - conn - for content in self._positional_connections.values() - for con_name, conn in content.items() - if con_name == source - ), - None, - ) + # Iterate over contents using direct key lookups to avoid O(N^2) generator overhead and preserve O(1) hash map access + for content in self._positional_connections.values(): + if source in content: + return content[source] + return None def get_positional_connections_by_source( self, source: ThingNameT, *, language: SemanticSearchLanguage | None = None