summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-07-06 21:56:27 +0000
committerZac Medico <zmedico@gentoo.org>2009-07-06 21:56:27 +0000
commit317ec856890cfca41c4655dd638e5804ce50b95c (patch)
treee0b3f84fcb07ccff87da8c141c8e5f304ffd16c9
parent1d13ae1ea7d44d6ecfdd401be4c4d867b61ff632 (diff)
downloadportage-317ec856890cfca41c4655dd638e5804ce50b95c.tar.gz
portage-317ec856890cfca41c4655dd638e5804ce50b95c.tar.bz2
portage-317ec856890cfca41c4655dd638e5804ce50b95c.zip
Optimize dbapi._iter_match_use() so that it shares a single compiled regex
for all implicit iuse checks. This avoids lots of expensibe re.compile() calls. Thanks to Marat Radchenko <slonopotamusorama@gmail.com> for the initial patch. svn path=/main/trunk/; revision=13801
-rw-r--r--pym/portage/dbapi/__init__.py14
-rw-r--r--pym/portage/dbapi/porttree.py1
2 files changed, 7 insertions, 8 deletions
diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
index abd6cc870..08b7a3b9b 100644
--- a/pym/portage/dbapi/__init__.py
+++ b/pym/portage/dbapi/__init__.py
@@ -23,7 +23,7 @@ class dbapi(object):
_category_re = re.compile(r'^\w[-.+\w]*$')
_pkg_dir_name_re = re.compile(r'^\w[-+\w]*$')
_categories = None
- _iuse_implicit = None
+ _iuse_implicit_re = None
_use_mutable = False
_known_keys = frozenset(x for x in auxdbkeys
if not x.startswith("UNUSED_0"))
@@ -149,20 +149,20 @@ class dbapi(object):
1) Check for required IUSE intersection (need implicit IUSE here).
2) Check enabled/disabled flag states.
"""
- if self._iuse_implicit is None:
- self._iuse_implicit = self.settings._get_implicit_iuse()
+ if self._iuse_implicit_re is None:
+ self._iuse_implicit_re = re.compile("^(%s)$" % \
+ "|".join(self.settings._get_implicit_iuse()))
+ iuse_implicit_re = self._iuse_implicit_re
for cpv in cpv_iter:
try:
iuse, slot, use = self.aux_get(cpv, ["IUSE", "SLOT", "USE"])
except KeyError:
continue
use = use.split()
- iuse = self._iuse_implicit.union(
- re.escape(x.lstrip("+-")) for x in iuse.split())
- iuse_re = re.compile("^(%s)$" % "|".join(iuse))
+ iuse = frozenset(x.lstrip('+-') for x in iuse.split())
missing_iuse = False
for x in atom.use.required:
- if iuse_re.match(x) is None:
+ if x not in iuse and iuse_implicit_re.match(x) is None:
missing_iuse = True
break
if missing_iuse:
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index 7c886ae25..e29377f72 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -133,7 +133,6 @@ class portdbapi(dbapi):
else:
from portage import settings
self.mysettings = config(clone=settings)
- self._iuse_implicit = self.mysettings._get_implicit_iuse()
self._categories = self.mysettings.categories
# This is strictly for use in aux_get() doebuild calls when metadata
# is generated by the depend phase. It's safest to use a clone for