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

raymond.hettinger python-checkins at python.org
Sat Feb 21 09:58:42 CET 2009


Author: raymond.hettinger
Date: Sat Feb 21 09:58:42 2009
New Revision: 69838

Log:
Speedup and simplify negative counter using count's new step argument.

Modified:
   python/trunk/Lib/heapq.py

Modified: python/trunk/Lib/heapq.py
==============================================================================
--- python/trunk/Lib/heapq.py	(original)
+++ python/trunk/Lib/heapq.py	Sat Feb 21 09:58:42 2009
@@ -130,7 +130,7 @@
            'nlargest', 'nsmallest', 'heappushpop']
 
 from itertools import islice, repeat, count, imap, izip, tee, chain
-from operator import itemgetter, neg
+from operator import itemgetter
 import bisect
 
 def heappush(heap, item):
@@ -413,13 +413,13 @@
 
     # When key is none, use simpler decoration
     if key is None:
-        it = izip(iterable, imap(neg, count()))             # decorate
+        it = izip(iterable, count(0,-1))                    # decorate
         result = _nlargest(n, it)
         return map(itemgetter(0), result)                   # undecorate
 
     # General case, slowest method
     in1, in2 = tee(iterable)
-    it = izip(imap(key, in1), imap(neg, count()), in2)      # decorate
+    it = izip(imap(key, in1), count(0,-1), in2)             # decorate
     result = _nlargest(n, it)
     return map(itemgetter(2), result)                       # undecorate
 


More information about the Python-checkins mailing list