[Python-checkins] r53822 - python/trunk/Lib/heapq.py

raymond.hettinger python-checkins at python.org
Mon Feb 19 07:59:32 CET 2007


Author: raymond.hettinger
Date: Mon Feb 19 07:59:32 2007
New Revision: 53822

Modified:
   python/trunk/Lib/heapq.py
Log:
Use C heapreplace() instead of slower _siftup() in pure python.

Modified: python/trunk/Lib/heapq.py
==============================================================================
--- python/trunk/Lib/heapq.py	(original)
+++ python/trunk/Lib/heapq.py	Mon Feb 19 07:59:32 2007
@@ -319,7 +319,7 @@
     [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_append = h.append
@@ -337,7 +337,7 @@
                 v, itnum, next = s = h[0]   # raises IndexError when h is empty
                 yield v
                 s[0] = next()               # raises StopIteration when exhausted
-                siftup(h, 0)                # restore heap condition
+                _heapreplace(h, s)          # restore heap condition
         except _StopIteration:
             _heappop(h)                     # remove empty iterator
         except IndexError:


More information about the Python-checkins mailing list