jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340521?usp=email )

Change subject: itertools: Short-circuit intersection cache checks
......................................................................

itertools: Short-circuit intersection cache checks

Check each cached counter's keys against the active source indices
instead of building their complete union on every iteration after a
source is exhausted. Stop checking as soon as a counter contains an
exhausted source.

Preserve the termination condition, output order, duplicate handling,
and input consumption while avoiding the temporary set.

Change-Id: I41d3b0393cad590a5e9502e0ce9765285f4a175d
---
M pywikibot/tools/itertools.py
1 file changed, 3 insertions(+), 6 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/pywikibot/tools/itertools.py b/pywikibot/tools/itertools.py
index 7ad1a26..2051278 100644
--- a/pywikibot/tools/itertools.py
+++ b/pywikibot/tools/itertools.py
@@ -194,13 +194,10 @@
                 else:
                     cache[item] -= ones

-        # We can quit if an iterable is exceeded and cached iterables is
-        # a subset of active iterables.
+        # We can quit if a source is exhausted and every cached item has
+        # only been found in sources which are still active.
         if len(active_iterables) < n_gen:
-            cached_iterables = set(
-                itertools.chain.from_iterable(v.keys()
-                                              for v in cache.values()))
-            if cached_iterables <= active_iterables:
+            if all(v.keys() <= active_iterables for v in cache.values()):
                 return



--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340521?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I41d3b0393cad590a5e9502e0ce9765285f4a175d
Gerrit-Change-Number: 1340521
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to