From 0afb7096deecab237b87a6d000aa55ef03ed6891 Mon Sep 17 00:00:00 2001 From: Alchav <59858495+Alchav@users.noreply.github.com> Date: Wed, 12 Oct 2022 23:46:07 -0400 Subject: [PATCH] Core: improve sweep_for_events efficiency (#1092) --- BaseClasses.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index d32749f5..d91be28c 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -689,14 +689,14 @@ class CollectionState(): def sweep_for_events(self, key_only: bool = False, locations: Optional[Iterable[Location]] = None) -> None: if locations is None: locations = self.world.get_filled_locations() - new_locations = True + reachable_events = True # since the loop has a good chance to run more than once, only filter the events once locations = {location for location in locations if location.event and not key_only or getattr(location.item, "locked_dungeon_item", False)} - while new_locations: + while reachable_events: reachable_events = {location for location in locations if location.can_reach(self)} - new_locations = reachable_events - self.events - for event in new_locations: + locations -= reachable_events + for event in reachable_events: self.events.add(event) assert isinstance(event.item, Item), "tried to collect Event with no Item" self.collect(event.item, True, event)