summaryrefslogtreecommitdiffstats
path: root/Lib/heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-05-27 00:08:27 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-05-27 00:08:27 (GMT)
commitab09c1319bde7a2ad756e7ed5651cfbb9848d271 (patch)
tree3435045756e5947bb8a085dc56c29825d5685527 /Lib/heapq.py
parent9f4c963e7ab64a9051e944c6dfdace268c6dd086 (diff)
downloadcpython-ab09c1319bde7a2ad756e7ed5651cfbb9848d271.zip
cpython-ab09c1319bde7a2ad756e7ed5651cfbb9848d271.tar.gz
cpython-ab09c1319bde7a2ad756e7ed5651cfbb9848d271.tar.bz2
Minor clean-ups for heapq.merge().
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r--Lib/heapq.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index 121a9bb..ae7ac96 100644
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -322,32 +322,31 @@ def merge(*iterables):
[0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
'''
- _heappop, _heapreplace, _StopIteration = heappop, heapreplace, StopIteration
- _len = len
h = []
h_append = h.append
- for itnum, it in enumerate(map(iter, iterables)):
+ for order, it in enumerate(map(iter, iterables)):
try:
next = it.__next__
- h_append([next(), itnum, next])
- except _StopIteration:
+ h_append([next(), order, next])
+ except StopIteration:
pass
heapify(h)
- while _len(h) > 1:
+ _heapreplace = heapreplace
+ while len(h) > 1:
try:
while True:
- v, itnum, next = s = h[0]
- yield v
- s[0] = next() # raises StopIteration when exhausted
- _heapreplace(h, s) # restore heap condition
- except _StopIteration:
- _heappop(h) # remove empty iterator
+ value, order, next = s = h[0]
+ yield value
+ s[0] = next() # raises StopIteration when exhausted
+ _heapreplace(h, s) # restore heap condition
+ except StopIteration:
+ heappop(h) # remove empty iterator
if h:
# fast case when only a single iterator remains
- v, itnum, next = h[0]
- yield v
+ value, order, next = h[0]
+ yield value
yield from next.__self__