Use C heapreplace() instead of slower _siftup() in pure python.
This commit is contained in:
parent
54da9819cc
commit
45eb0f1419
|
@ -319,7 +319,7 @@ def merge(*iterables):
|
||||||
[0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
|
[0, 1, 2, 3, 4, 5, 5, 7, 8, 10, 15, 20, 25]
|
||||||
|
|
||||||
'''
|
'''
|
||||||
_heappop, siftup, _StopIteration = heappop, _siftup, StopIteration
|
_heappop, _heapreplace, _StopIteration = heappop, heapreplace, StopIteration
|
||||||
|
|
||||||
h = []
|
h = []
|
||||||
h_append = h.append
|
h_append = h.append
|
||||||
|
@ -337,7 +337,7 @@ def merge(*iterables):
|
||||||
v, itnum, next = s = h[0] # raises IndexError when h is empty
|
v, itnum, next = s = h[0] # raises IndexError when h is empty
|
||||||
yield v
|
yield v
|
||||||
s[0] = next() # raises StopIteration when exhausted
|
s[0] = next() # raises StopIteration when exhausted
|
||||||
siftup(h, 0) # restore heap condition
|
_heapreplace(h, s) # restore heap condition
|
||||||
except _StopIteration:
|
except _StopIteration:
|
||||||
_heappop(h) # remove empty iterator
|
_heappop(h) # remove empty iterator
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
Loading…
Reference in New Issue