diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-09-24 14:18:41 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-09-24 14:18:41 -0700 |
commit | 03adf83487276541b619396bdf79812b38ee8422 (patch) | |
tree | 20770435e09eabafd435f2a1f82b1a5a5fdb99b3 | |
parent | 75907929be736e2d4cf088d8d9861f2666e59557 (diff) | |
download | portage-03adf83487276541b619396bdf79812b38ee8422.tar.gz portage-03adf83487276541b619396bdf79812b38ee8422.tar.bz2 portage-03adf83487276541b619396bdf79812b38ee8422.zip |
portdbapi.xmatch: combine *-visible code
This allows match-visible to avoid calling match-all, which allows it
to avoid an extra loop over all repos.
-rw-r--r-- | pym/portage/dbapi/porttree.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py index 782cecccc..d5068abd5 100644 --- a/pym/portage/dbapi/porttree.py +++ b/pym/portage/dbapi/porttree.py @@ -887,12 +887,6 @@ class portdbapi(dbapi): if len(myval) > 1: self._cpv_sort_ascending(myval) - elif level == "match-visible": - # find all visible matches - myval = self.xmatch("match-all", mydep) - if myval: - myval = list(self._iter_visible(myval, myrepo=mydep.repo)) - elif level == "minimum-all": # Find the minimum matching version. This is optimized to # minimize the number of metadata accesses (improves performance @@ -916,7 +910,7 @@ class portdbapi(dbapi): if myval: break - elif level in ("minimum-visible", "bestmatch-visible"): + elif level in ("match-visible", "minimum-visible", "bestmatch-visible"): # Find the minimum matching visible version. This is optimized to # minimize the number of metadata accesses (improves performance # especially in cases where metadata needs to be generated). @@ -925,12 +919,14 @@ class portdbapi(dbapi): else: mylist = match_from_list(mydep, self.cp_list(mykey, mytree=mytree)) - myval = "" + + single_match = level != "match-visible" + myval = [] aux_keys = list(self._aux_cache_keys) - if level == "minimum-visible": - iterfunc = iter - else: + if level == "bestmatch-visible": iterfunc = reversed + else: + iterfunc = iter if mydep.repo is not None: repos = [mydep.repo] @@ -961,11 +957,19 @@ class portdbapi(dbapi): not self._match_use(mydep, cpv, metadata): continue - myval = cpv + myval.append(cpv) + # only yield a given cpv once break - if myval: + + if myval and single_match: break + if single_match: + if myval: + myval = myval[0] + else: + myval = "" + elif level == "bestmatch-list": #dep match -- find best match but restrict search to sublist warnings.warn("The 'bestmatch-list' mode of " |