commit: 646b671d4afb92e0bb81664568544e01e8456dc2
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Nov 7 07:58:19 2014 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Dec 7 23:10:48 2014 +0000
URL:
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=646b671d
search: optimize desc search with _first_cp
---
pym/_emerge/search.py | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/pym/_emerge/search.py b/pym/_emerge/search.py
index 4b1833a..90dbcec 100644
--- a/pym/_emerge/search.py
+++ b/pym/_emerge/search.py
@@ -123,6 +123,23 @@ class search(object):
cpv=cpv, built=built, installed=installed,
metadata=metadata).visible
+ def _first_cp(self, cp):
+
+ for db in self._dbs:
+ if hasattr(db, "cp_list"):
+ matches = db.cp_list(cp)
+ if matches:
+ return matches[-1]
+ else:
+ matches = db.match(cp)
+
+ for cpv in matches:
+ if cpv.cp == cp:
+ return cpv
+
+ return None
+
+
def _xmatch(self, level, atom):
"""
This method does not expand old-style virtuals because it
@@ -230,13 +247,12 @@ class search(object):
if self.searchre.search(match_string):
yield ("pkg", package)
elif self.searchdesc: # DESCRIPTION searching
- # Use match-all to avoid an expensive
visibility check,
+ # Use _first_cp to avoid an expensive
visibility check,
# since the visibility check can be avoided
entirely
# when the DESCRIPTION does not match.
- full_package = self._xmatch("match-all",
package)
+ full_package = self._first_cp(package)
if not full_package:
continue
- full_package = full_package[-1]
try:
full_desc = self._aux_get(
full_package,
["DESCRIPTION"])[0]