From 03adf83487276541b619396bdf79812b38ee8422 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 24 Sep 2011 14:18:41 -0700 Subject: 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. --- pym/portage/dbapi/porttree.py | 30 +++++++++++++++++------------- 1 file 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 " -- cgit v1.2.3-1-g7c22