Cache results for Task.__hash__() calls.
authorZac Medico <zmedico@gentoo.org>
Mon, 5 May 2008 21:06:30 +0000 (21:06 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 5 May 2008 21:06:30 +0000 (21:06 -0000)
svn path=/main/trunk/; revision=10210

pym/_emerge/__init__.py

index 378b4e21d0e1f76547050f51dc547c1527ad5581..1baaff7f8f107dab84926aa5ebfbcf15de21a14f 100644 (file)
@@ -1220,7 +1220,7 @@ def show_masked_packages(masked_packages):
        return have_eapi_mask
 
 class Task(SlotObject):
-       __slots__ = ("_hash_key",)
+       __slots__ = ("_hash_key", "_hash_value")
 
        def _get_hash_key(self):
                hash_key = getattr(self, "_hash_key", None)
@@ -1235,7 +1235,10 @@ class Task(SlotObject):
                return self._get_hash_key() != other
 
        def __hash__(self):
-               return hash(self._get_hash_key())
+               hash_value = getattr(self, "_hash_value", None)
+               if hash_value is None:
+                       self._hash_value = hash(self._get_hash_key())
+               return self._hash_value
 
        def __len__(self):
                return len(self._get_hash_key())