summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-06-05 00:10:17 -0700
committerZac Medico <zmedico@gentoo.org>2011-06-05 00:10:17 -0700
commite390b1d43556d665ca3356317ab843bd68cbfe14 (patch)
tree6a9068e68d64210a4592b2995d902111e6ba1906
parent70c1c399615ae3a2ed15d1684a99f32126305d15 (diff)
downloadportage-e390b1d43556d665ca3356317ab843bd68cbfe14.tar.gz
portage-e390b1d43556d665ca3356317ab843bd68cbfe14.tar.bz2
portage-e390b1d43556d665ca3356317ab843bd68cbfe14.zip
dep_expand: optimize away cpv_expand if possible
-rw-r--r--pym/portage/dbapi/dep_expand.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/pym/portage/dbapi/dep_expand.py b/pym/portage/dbapi/dep_expand.py
index 60e30df87..afd8b4f13 100644
--- a/pym/portage/dbapi/dep_expand.py
+++ b/pym/portage/dbapi/dep_expand.py
@@ -14,14 +14,14 @@ def dep_expand(mydep, mydb=None, use_cache=1, settings=None):
'''
@rtype: Atom
'''
- if not len(mydep):
- return mydep
- if mydep[0]=="*":
- mydep=mydep[1:]
orig_dep = mydep
if isinstance(orig_dep, Atom):
- mydep = orig_dep.cp
+ has_cat = True
else:
+ if not mydep:
+ return mydep
+ if mydep[0] == "*":
+ mydep = mydep[1:]
mydep = orig_dep
has_cat = '/' in orig_dep
if not has_cat:
@@ -40,8 +40,17 @@ def dep_expand(mydep, mydb=None, use_cache=1, settings=None):
if not has_cat:
null_cat, pn = catsplit(mydep.cp)
mydep = pn
- else:
- mydep = mydep.cp
+
+ if has_cat:
+ # Optimize most common cases to avoid calling cpv_expand.
+ if not mydep.cp.startswith("virtual/"):
+ return mydep
+ if not hasattr(mydb, "cp_list") or \
+ mydb.cp_list(mydep.cp):
+ return mydep
+ # Fallback to legacy cpv_expand for old-style PROVIDE virtuals.
+ mydep = mydep.cp
+
expanded = cpv_expand(mydep, mydb=mydb,
use_cache=use_cache, settings=settings)
return Atom(orig_dep.replace(mydep, expanded, 1), allow_repo=True)