Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f2762321
Commit
f2762321
authored
Sep 11, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18962: Optimize the single iterator case for heapq.merge()
Suggested by Wouter Bolsterlee.
parent
aa1004da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
5 deletions
+10
-5
Lib/heapq.py
Lib/heapq.py
+9
-5
Misc/ACKS
Misc/ACKS
+1
-0
No files found.
Lib/heapq.py
View file @
f2762321
...
...
@@ -358,6 +358,7 @@ def merge(*iterables):
'''
_heappop
,
_heapreplace
,
_StopIteration
=
heappop
,
heapreplace
,
StopIteration
_len
=
len
h
=
[]
h_append
=
h
.
append
...
...
@@ -369,17 +370,20 @@ def merge(*iterables):
pass
heapify
(
h
)
while
1
:
while
_len
(
h
)
>
1
:
try
:
while
1
:
v
,
itnum
,
next
=
s
=
h
[
0
]
# raises IndexError when h is empty
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
except
IndexError
:
return
if
h
:
# fast case when only a single iterator remains
v
,
itnum
,
next
=
h
[
0
]
yield
v
yield
from
next
.
__self__
# Extend the implementations of nsmallest and nlargest to use a key= argument
_nsmallest
=
nsmallest
...
...
Misc/ACKS
View file @
f2762321
...
...
@@ -135,6 +135,7 @@ Paul Boddie
Matthew Boedicker
Robin Boerdijk
David Bolen
Wouter Bolsterlee
Gawain Bolton
Forest Bond
Gregory Bond
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment