Optimize dbapi._iter_match_use() so that it shares a single compiled regex
authorZac Medico <zmedico@gentoo.org>
Mon, 6 Jul 2009 21:56:27 +0000 (21:56 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 6 Jul 2009 21:56:27 +0000 (21:56 -0000)
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

pym/portage/dbapi/__init__.py
pym/portage/dbapi/porttree.py

index abd6cc870d2ebf2eabe5440f727c03542617ff4f..08b7a3b9bf645948135a2981333bb450a0dfd969 100644 (file)
@@ -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:
index 7c886ae259272d005c3186bb8384cbd3d2e91095..e29377f72304c139b3136081fd0d36038ee6dd9a 100644 (file)
@@ -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