Use any() to optimize intersection operations.
authorZac Medico <zmedico@gentoo.org>
Wed, 30 May 2012 22:36:31 +0000 (15:36 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 30 May 2012 22:36:31 +0000 (15:36 -0700)
pym/_emerge/depgraph.py
pym/portage/dbapi/__init__.py
pym/portage/dep/__init__.py
pym/repoman/checks.py

index be49b0f70da1beb5b0c5c0bd088ef7739c06237d..935c37642e17e1723ae0c539c122a8ed94291e50 100644 (file)
@@ -2390,22 +2390,20 @@ class depgraph(object):
                except self._unknown_internal_error:
                        return False, myfavorites
 
-               digraph_set = frozenset(self._dynamic_config.digraph)
+               digraph_nodes = self._dynamic_config.digraph.nodes
 
-               if digraph_set.intersection(
+               if any(x in digraph_nodes for x in
                        self._dynamic_config._needed_unstable_keywords) or \
-                       digraph_set.intersection(
+                       any(x in digraph_nodes for x in
                        self._dynamic_config._needed_p_mask_changes) or \
-                       digraph_set.intersection(
+                       any(x in digraph_nodes for x in
                        self._dynamic_config._needed_use_config_changes) or \
-                       digraph_set.intersection(
+                       any(x in digraph_nodes for x in
                        self._dynamic_config._needed_license_changes) :
                        #We failed if the user needs to change the configuration
                        self._dynamic_config._success_without_autounmask = True
                        return False, myfavorites
 
-               digraph_set = None
-
                if self._rebuild.trigger_rebuilds():
                        backtrack_infos = self._dynamic_config._backtrack_infos
                        config = backtrack_infos.setdefault("config", {})
@@ -3083,7 +3081,7 @@ class depgraph(object):
 
                                untouchable_flags = \
                                        frozenset(chain(pkg.use.mask, pkg.use.force))
-                               if untouchable_flags.intersection(
+                               if any(x in untouchable_flags for x in
                                        chain(need_enable, need_disable)):
                                        continue
 
@@ -3133,7 +3131,7 @@ class depgraph(object):
 
                                        untouchable_flags = \
                                                frozenset(chain(myparent.use.mask, myparent.use.force))
-                                       if untouchable_flags.intersection(involved_flags):
+                                       if any(x in untouchable_flags for x in involved_flags):
                                                continue
 
                                        required_use = myparent.metadata.get("REQUIRED_USE")
@@ -3758,7 +3756,7 @@ class depgraph(object):
                        new_use, changes = self._dynamic_config._needed_use_config_changes.get(pkg)
                        for ppkg, atom in parent_atoms:
                                if not atom.use or \
-                                       not atom.use.required.intersection(changes):
+                                       not any(x in atom.use.required for x in changes):
                                        continue
                                else:
                                        return True
@@ -3772,8 +3770,8 @@ class depgraph(object):
                                not check_required_use(required_use, new_use, pkg.iuse.is_valid_flag):
                                return old_use
 
-                       if pkg.use.mask.intersection(new_changes) or \
-                               pkg.use.force.intersection(new_changes):
+                       if any(x in pkg.use.mask for x in new_changes) or \
+                               any(x in pkg.use.force for x in new_changes):
                                return old_use
 
                        self._dynamic_config._needed_use_config_changes[pkg] = (new_use, new_changes)
@@ -4004,7 +4002,7 @@ class depgraph(object):
                                                missing_disabled = atom.use.missing_disabled.difference(pkg.iuse.all)
 
                                                if atom.use.enabled:
-                                                       if atom.use.enabled.intersection(missing_disabled):
+                                                       if any(x in atom.use.enabled for x in missing_disabled):
                                                                use_match = False
                                                                can_adjust_use = False
                                                        need_enabled = atom.use.enabled.difference(use)
@@ -4013,11 +4011,11 @@ class depgraph(object):
                                                                if need_enabled:
                                                                        use_match = False
                                                                        if can_adjust_use:
-                                                                               if pkg.use.mask.intersection(need_enabled):
+                                                                               if any(x in pkg.use.mask for x in need_enabled):
                                                                                        can_adjust_use = False
 
                                                if atom.use.disabled:
-                                                       if atom.use.disabled.intersection(missing_enabled):
+                                                       if any(x in atom.use.disabled for x in missing_enabled):
                                                                use_match = False
                                                                can_adjust_use = False
                                                        need_disabled = atom.use.disabled.intersection(use)
@@ -4026,8 +4024,8 @@ class depgraph(object):
                                                                if need_disabled:
                                                                        use_match = False
                                                                        if can_adjust_use:
-                                                                               if pkg.use.force.difference(
-                                                                                       pkg.use.mask).intersection(need_disabled):
+                                                                               if any(x in pkg.use.force and x not in
+                                                                                       pkg.use.mask for x in need_disabled):
                                                                                        can_adjust_use = False
 
                                                if not use_match:
@@ -5241,7 +5239,7 @@ class depgraph(object):
                                                                        for node in nodes:
                                                                                parents = mygraph.parent_nodes(node,
                                                                                        ignore_priority=DepPrioritySatisfiedRange.ignore_soft)
-                                                                               if parents and set(parents).intersection(asap_nodes):
+                                                                               if any(x in asap_nodes for x in parents):
                                                                                        selected_nodes = [node]
                                                                                        break
                                                                else:
index a1c5c567460706cfd1a5deebe18d4a9e6848197d..a90d59e77634ab38210f3770e1e8973b11c0e7b2 100644 (file)
@@ -190,21 +190,19 @@ class dbapi(object):
                        missing_disabled = atom.use.missing_disabled.difference(iuse)
 
                        if atom.use.enabled:
-                               if atom.use.enabled.intersection(missing_disabled):
+                               if any(x in atom.use.enabled for x in missing_disabled):
                                        return False
                                need_enabled = atom.use.enabled.difference(use)
                                if need_enabled:
-                                       need_enabled = need_enabled.difference(missing_enabled)
-                                       if need_enabled:
+                                       if any(x not in missing_enabled for x in need_enabled):
                                                return False
 
                        if atom.use.disabled:
-                               if atom.use.disabled.intersection(missing_enabled):
+                               if any(x in atom.use.disabled for x in missing_enabled):
                                        return False
                                need_disabled = atom.use.disabled.intersection(use)
                                if need_disabled:
-                                       need_disabled = need_disabled.difference(missing_disabled)
-                                       if need_disabled:
+                                       if any(x not in missing_disabled for x in need_disabled):
                                                return False
 
                elif not self.settings.local_config:
@@ -215,11 +213,12 @@ class dbapi(object):
                                pkg = _pkg_str(cpv, slot=metadata["SLOT"],
                                        repo=metadata.get("repository"))
                        usemask = self.settings._getUseMask(pkg)
-                       if usemask.intersection(atom.use.enabled):
+                       if any(x in usemask for x in atom.use.enabled):
                                return False
 
-                       useforce = self.settings._getUseForce(pkg).difference(usemask)
-                       if useforce.intersection(atom.use.disabled):
+                       useforce = self.settings._getUseForce(pkg)
+                       if any(x in useforce and x not in usemask
+                               for x in atom.use.disabled):
                                return False
 
                return True
index d29a4c4a1c63693d7808ca1fb985a117d6a2616a..4cd081310e402e163b13184654800dc9292f6257 100644 (file)
@@ -2081,21 +2081,19 @@ def match_from_list(mydep, candidate_list):
                                        missing_disabled = mydep.use.missing_disabled.difference(x.iuse.all)
 
                                        if mydep.use.enabled:
-                                               if mydep.use.enabled.intersection(missing_disabled):
+                                               if any(f in mydep.use.enabled for f in missing_disabled):
                                                        continue
                                                need_enabled = mydep.use.enabled.difference(use.enabled)
                                                if need_enabled:
-                                                       need_enabled = need_enabled.difference(missing_enabled)
-                                                       if need_enabled:
+                                                       if any(f not in missing_enabled for f in need_enabled):
                                                                continue
 
                                        if mydep.use.disabled:
-                                               if mydep.use.disabled.intersection(missing_enabled):
+                                               if any(f in mydep.use.disabled for f in missing_enabled):
                                                        continue
                                                need_disabled = mydep.use.disabled.intersection(use.enabled)
                                                if need_disabled:
-                                                       need_disabled = need_disabled.difference(missing_disabled)
-                                                       if need_disabled:
+                                                       if any(f not in missing_disabled for f in need_disabled):
                                                                continue
 
                        mylist.append(x)
index 35225c2293ab598b7549ecf8ff5a86c4ad470dc0..94dcfbea899cff2fdf7c2d040c743953a72ef1f4 100644 (file)
@@ -470,7 +470,7 @@ class InheritEclass(LineCheck):
                self._inherit = False
                self._func_call = False
                if hasattr(self, '_exempt_eclasses'):
-                       self._disabled = self._exempt_eclasses.intersection(pkg.inherited)
+                       self._disabled = any(x in pkg.inherited for x in self._exempt_eclasses)
                else:
                        self._disabled = False