From: Zac Medico Date: Wed, 11 Mar 2009 05:57:06 +0000 (-0000) Subject: Optimize depgraph._dep_expand() to avoid calling pordbapi.cp_all(), X-Git-Tag: v2.1.6.8~156 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=28355b368a48e1da35921fc347b5347b782a3094;p=portage.git Optimize depgraph._dep_expand() to avoid calling pordbapi.cp_all(), since it can be more efficient to call cp_list() on each category. Thanks to Marat Radchenko for the suggestion. (trunk r12653) svn path=/main/branches/2.1.6/; revision=12921 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index f5505d85a..b2e5c37fc 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -5258,23 +5258,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 diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index e5db363d7..dae7ad014 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -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): diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 77e6ae494..d342c22d9 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -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