From 317ec856890cfca41c4655dd638e5804ce50b95c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 6 Jul 2009 21:56:27 +0000 Subject: 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 for the initial patch. svn path=/main/trunk/; revision=13801 --- pym/portage/dbapi/__init__.py | 14 +++++++------- pym/portage/dbapi/porttree.py | 1 - 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 -- cgit v1.2.3-1-g7c22