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>
Fri, 20 May 2011 04:52:28 +0000 (21:52 -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 2dfcc8502f72930f7ee6bb69e4d7e9313f5e48f2..12fa537aa54591d1cd44c792b7214072c58fdc61 100644 (file)
@@ -81,6 +81,15 @@ class Package(Task):
                        else:
                                self.operation = "merge"
 
+               # For installed (and binary) packages we don't care for the repo
+               # when it comes to hashing, because there can only be one cpv.
+               # So overwrite the repo_key with type_name.
+               repo_key = self.metadata.get('repository')
+               if self.type_name != 'ebuild':
+                       repo_key = self.type_name
+               self._hash_key = \
+                       (self.type_name, self.root, self.cpv, self.operation, repo_key)
+
        def _validate_deps(self):
                """
                Validate deps. This does not trigger USE calculation since that
@@ -266,7 +275,6 @@ class Package(Task):
                        self.cpv, self.metadata)
                return pmask is not None
 
-
        def _metadata_exception(self, k, e):
 
                # For unicode safety with python-2.x we need to avoid
@@ -453,16 +461,6 @@ class Package(Task):
                        return missing_iuse
 
        def _get_hash_key(self):
-               hash_key = getattr(self, "_hash_key", None)
-               if hash_key is None:
-                       # For installed (and binary) packages we don't care for the repo
-                       # when it comes to hashing, because there can only be one cpv.
-                       # So overwrite the repo_key with type_name.
-                       repo_key = self.metadata.get('repository')
-                       if self.type_name != 'ebuild':
-                               repo_key = self.type_name
-                       self._hash_key = \
-                               (self.type_name, self.root, self.cpv, self.operation, repo_key)
                return self._hash_key
 
        def __len__(self):