xyzgrid: Replace nested look with dict lookup & short list filter

Upstream is O(n^2) time complexity due to nested loop. Diff includes O(1) dict look up with short filter. Symbol_map is already built during `XYMap.parse()`.
This commit is contained in:
Jake 2026-02-15 05:56:18 -08:00 committed by GitHub
parent 172d5162f0
commit 49e2066446
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -946,16 +946,14 @@ class SmartTeleporterMapLink(MapLink):
'pointing to an empty space' error we'd get if returning `None`.
"""
xygrid = self.xymap.xygrid
if not self.paired_teleporter:
# scan for another teleporter
symbol = self.symbol
found_teleporters = []
for iy, line in xygrid.items():
for ix, node_or_link in xygrid[iy].items():
if node_or_link.symbol == symbol and node_or_link is not self:
found_teleporters.append(node_or_link)
# find the matching teleporter via pre-built symbol map
found_teleporters = [
comp
for comp in self.xymap.symbol_map.get(self.symbol, [])
if comp is not self
]
if not found_teleporters:
raise MapParserError("found no matching teleporter to link to.", self)
if len(found_teleporters) > 1: