From 4fea6b6e9b2564867eeef3bff943dcf7a00148cf Mon Sep 17 00:00:00 2001 From: Mysteryem Date: Sat, 5 Apr 2025 16:53:59 +0100 Subject: [PATCH] Core: Remove Location.__hash__ (#4274) `Location` does not override `__eq__` so should not override `__hash__`. With this patch, this makes operations on sets of locations slightly faster because they will use `object.__hash__` rather than `Location.__hash__`. `object.__hash__` is about 4 to 5 times faster than `Location.__hash__` for me. Generation often uses sets of locations, so this slightly speeds up generation. The only place I could find that was hashing locations directly was `WitnessLocationHint.__hash__`, but it has implemented a matching `__eq__`, so is fine. For security reasons, Python randomizes its hash seed each time it is started, so the result of the `hash()` function is nondeterministic and can't have been used by worlds for anything that needed to be deterministic and can't have been used to compare information hashed at generation time to information hashed by a client. --- BaseClasses.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/BaseClasses.py b/BaseClasses.py index 84e54d7e..781fef0e 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -1313,9 +1313,6 @@ class Location: multiworld = self.parent_region.multiworld if self.parent_region and self.parent_region.multiworld else None return multiworld.get_name_string_for_object(self) if multiworld else f'{self.name} (Player {self.player})' - def __hash__(self): - return hash((self.name, self.player)) - def __lt__(self, other: Location): return (self.player, self.name) < (other.player, other.name)