Optimize USE_EXPAND -> USE code inside config.setcpv(). Thanks to
authorZac Medico <zmedico@gentoo.org>
Sun, 12 Jul 2009 23:04:43 +0000 (23:04 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 12 Jul 2009 23:04:43 +0000 (23:04 -0000)
Marat Radchenko <slonopotamusorama@gmail.com> for the initial patch
from bug #276813.

svn path=/main/trunk/; revision=13823

pym/portage/__init__.py

index 4dc62fa5a4f7bb973e16770ee1a161c09da597b0..d78491c4d3192e499438d43f6f2c20f885f881e1 100644 (file)
@@ -2386,27 +2386,37 @@ class config(object):
                # Use the calculated USE flags to regenerate the USE_EXPAND flags so
                # that they are consistent. For optimal performance, use slice
                # comparison instead of startswith().
-               use_expand_split = set(self.get("USE_EXPAND", "").split())
+               use_expand_split = set(x.lower() for \
+                       x in self.get('USE_EXPAND', '').split())
                lazy_use_expand = self._lazy_use_expand(use, self.usemask,
                        iuse_implicit, use_expand_split, self._use_expand_dict)
-               for key in use_expand_split:
-                       prefix = key.lower() + '_'
-                       prefix_len = len(prefix)
-                       use_expand_iuse = set( x for x in iuse_implicit \
-                               if x[:prefix_len] == prefix )
-                       # * means to enable everything in IUSE that's not masked
-                       if use_expand_iuse:
-                               if prefix + '*' in use:
-                                       use.update( use_expand_iuse.difference(usemask) )
-                               self.configdict['env'].addLazySingleton(
-                                       key, lazy_use_expand.__getitem__, key)
-                       else:
-                               # It's not in IUSE, so just allow the variable content
-                               # to pass through if it is defined somewhere.  This
-                               # allows packages that support LINGUAS but don't
-                               # declare it in IUSE to use the variable outside of the
-                               # USE_EXPAND context.
-                               pass
+
+               use_expand_iuses = {}
+               for x in iuse_implicit:
+                       x_split = x.split('_')
+                       if len(x_split) == 1:
+                               continue
+                       for i in xrange(len(x_split) - 1):
+                               k = '_'.join(x_split[:i+1])
+                               if k in use_expand_split:
+                                       v = use_expand_iuses.get(k)
+                                       if v is None:
+                                               v = set()
+                                               use_expand_iuses[k] = v
+                                       v.add(x)
+                                       break
+
+               # If it's not in IUSE, variable content is allowed
+               # to pass through if it is defined somewhere.  This
+               # allows packages that support LINGUAS but don't
+               # declare it in IUSE to use the variable outside of the
+               # USE_EXPAND context.
+               for k, use_expand_iuse in use_expand_iuses.iteritems():
+                       if k + '_*' in use:
+                               use.update( x for x in use_expand_iuse if x not in usemask )
+                       k = k.upper()
+                       self.configdict['env'].addLazySingleton(k,
+                               lazy_use_expand.__getitem__, k)
 
                # Filtered for the ebuild environment. Store this in a separate
                # attribute since we still want to be able to see global USE