Optimize xmatch "bestmatch-visible" to do fewer metadata
authorZac Medico <zmedico@gentoo.org>
Tue, 30 Oct 2007 21:48:11 +0000 (21:48 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 30 Oct 2007 21:48:11 +0000 (21:48 -0000)
accesses by using the same code as "minimum-visible" but
with a reverse iterator.

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

pym/portage/dbapi/porttree.py

index ec38e0850dfc6a0c36462ee83454d13671734a6f..aad3885088e22d05ca13d7154b226c463b07d0ac 100644 (file)
@@ -573,11 +573,6 @@ class portdbapi(dbapi):
                        #myval = self.visible(self.cp_list(mykey))
 
                        myval = self.gvisible(self.visible(self.cp_list(mykey)))
-               elif level == "bestmatch-visible":
-                       #dep match -- best match of all visible packages
-                       #get all visible matches (from xmatch()), then choose the best one
-
-                       myval = best(self.xmatch("match-visible", None, mydep=mydep, mykey=mykey))
                elif level == "minimum-all":
                        # Find the minimum matching version. This is optimized to
                        # minimize the number of metadata accesses (improves performance
@@ -598,7 +593,7 @@ class portdbapi(dbapi):
                                                                break
                                                except KeyError:
                                                        pass # ebuild masked by corruption
-               elif level == "minimum-visible":
+               elif level in ("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).
@@ -610,7 +605,11 @@ class portdbapi(dbapi):
                                mylist = match_from_list(mydep, self.cp_list(mykey))
                        myval = ""
                        settings = self.mysettings
-                       for cpv in mylist:
+                       if level == "minimum-visible":
+                               iterfunc = iter
+                       else:
+                               iterfunc = reversed
+                       for cpv in iterfunc(mylist):
                                try:
                                        metadata = dict(izip(self._aux_cache_keys,
                                                self.aux_get(cpv, self._aux_cache_keys)))