Package: precalculate _hash_key
authorMarat Radchenko <marat@slonopotamus.org>
Fri, 20 May 2011 04:25:17 +0000 (08:25 +0400)
committerZac Medico <zmedico@gentoo.org>
Thu, 26 May 2011 03:27:49 +0000 (20:27 -0700)
This eliminates an expensive getattr call in _get_hash_key(), which
greatly improves depgraph performance on a weak ARM cpu.

pym/_emerge/Package.py

index f11da6ee56bcbb5c189807cfe34497e0b74fd761..d7efbf2ae673d907ca84951f63335ccaf6167f9c 100644 (file)
@@ -73,6 +73,9 @@ class Package(Task):
                        else:
                                self.operation = "merge"
 
+               self._hash_key = \
+                       (self.type_name, self.root, self.cpv, self.operation)
+
        def _validate_deps(self):
                """
                Validate deps. This does not trigger USE calculation since that
@@ -405,10 +408,6 @@ class Package(Task):
                        return missing_iuse
 
        def _get_hash_key(self):
-               hash_key = getattr(self, "_hash_key", None)
-               if hash_key is None:
-                       self._hash_key = \
-                               (self.type_name, self.root, self.cpv, self.operation)
                return self._hash_key
 
        def __lt__(self, other):