]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
Issue #21424: Optimize heaqp.nlargest() to make fewer tuple comparisons.
authorRaymond Hettinger <python@rcn.com>
Sun, 11 May 2014 08:55:46 +0000 (01:55 -0700)
committerRaymond Hettinger <python@rcn.com>
Sun, 11 May 2014 08:55:46 +0000 (01:55 -0700)
commit277842eff12eba1ceeeba1cee93db3ec99d5c95a
treec88048d92f55d57585192c1274d8476d7ffc9ac9
parentd6a46ae7059a5597aab614226f345bfb7dd67c16
Issue #21424:  Optimize heaqp.nlargest() to make fewer tuple comparisons.

Consolidates the logic for nlargest() into a single function so that
decoration tuples (elem,order) or (key, order, elem) only need to
be formed when a new element is added to the heap.  Formerly, a tuple
was created for every element regardless of whether it was added to
the heap.

The change reduces the number of tuples created, the number of ordering
integers created, and total number of tuple comparisons.
Lib/heapq.py
Lib/test/test_heapq.py
Misc/NEWS
Modules/_heapqmodule.c