Optimize depgraph._dep_expand() to avoid calling pordbapi.cp_all(),
authorZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 19:01:26 +0000 (19:01 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 19:01:26 +0000 (19:01 -0000)
since it can be more efficient to call cp_list() on each category.
Thanks to Marat Radchenko <slonopotamusorama@gmail.com> for the
suggestion.

svn path=/main/trunk/; revision=12653

pym/_emerge/__init__.py
pym/portage/dbapi/__init__.py
pym/portage/dbapi/porttree.py

index a5802bbe55baa6916d608b95b6fba143d87a6546..be50a6386389e89199617f7c9b4e8dd68a52ee9e 100644 (file)
@@ -5274,23 +5274,14 @@ class depgraph(object):
                cat, atom_pn = portage.catsplit(null_cp)
 
                dbs = self._filtered_trees[root_config.root]["dbs"]
-               cp_set = set()
+               categories = set()
                for db, pkg_type, built, installed, db_keys in dbs:
-                       cp_set.update(db.cp_all())
-               for cp in list(cp_set):
-                       cat, pn = portage.catsplit(cp)
-                       if pn != atom_pn:
-                               cp_set.discard(cp)
+                       for cat in db.categories:
+                               if db.cp_list("%s/%s" % (cat, atom_pn)):
+                                       categories.add(cat)
+
                deps = []
-               for cp in cp_set:
-                       have_pkg = False
-                       for db, pkg_type, built, installed, db_keys in dbs:
-                               if db.cp_list(cp):
-                                       have_pkg = True
-                                       break
-                       if not have_pkg:
-                               continue
-                       cat, pn = portage.catsplit(cp)
+               for cat in categories:
                        deps.append(insert_category_into_atom(
                                atom_without_category, cat))
                return deps
index e5db363d7970f37bb70027d5e9b5f88ae496ca9e..dae7ad014f907b10c8656d685c64f25b70485c15 100644 (file)
@@ -38,8 +38,7 @@ class dbapi(object):
                cat_pattern = re.compile(r'(.*)/.*')
                for cp in self.cp_all():
                        categories.add(cat_pattern.match(cp).group(1))
-               self._categories = list(categories)
-               self._categories.sort()
+               self._categories = tuple(sorted(categories))
                return self._categories
 
        def close_caches(self):
index 77e6ae494c57d0b7f1aeea1214c1c4fac6e4bf55..d342c22d9b171fb1e2cf5e613e2b73b9468e280c 100644 (file)
@@ -94,7 +94,7 @@ class portdbapi(dbapi):
                        from portage import settings
                        self.mysettings = config(clone=settings)
                self._iuse_implicit = self.mysettings._get_implicit_iuse()
-               self._categories = set(self.mysettings.categories)
+               self._categories = tuple(sorted(set(self.mysettings.categories)))
                # This is strictly for use in aux_get() doebuild calls when metadata
                # is generated by the depend phase.  It's safest to use a clone for
                # this purpose because doebuild makes many changes to the config