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

bin/emerge

index 89e9a64309ed6994cfd807cf5ed550913f2599c6..4cc690f38af3ce88002a918e4dd8d372f3887037 100755 (executable)
@@ -1361,7 +1361,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)
@@ -1376,7 +1376,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())