[Python-checkins] cpython (2.7): Issue 13274: Make the pure python code for heapq more closely match the C
raymond.hettinger
python-checkins at python.org
Sun Oct 30 22:29:17 CET 2011
http://hg.python.org/cpython/rev/57f73b0f921c
changeset: 73221:57f73b0f921c
branch: 2.7
user: Raymond Hettinger <python at rcn.com>
date: Sun Oct 30 14:29:06 2011 -0700
summary:
Issue 13274: Make the pure python code for heapq more closely match the C implementation for an undefined corner case.
files:
Lib/heapq.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/Lib/heapq.py b/Lib/heapq.py
--- a/Lib/heapq.py
+++ b/Lib/heapq.py
@@ -193,6 +193,8 @@
Equivalent to: sorted(iterable, reverse=True)[:n]
"""
+ if n < 0:
+ return []
it = iter(iterable)
result = list(islice(it, n))
if not result:
@@ -209,6 +211,8 @@
Equivalent to: sorted(iterable)[:n]
"""
+ if n < 0:
+ return []
if hasattr(iterable, '__len__') and n * 10 <= len(iterable):
# For smaller values of n, the bisect method is faster than a minheap.
# It is also memory efficient, consuming only n elements of space.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list