mirror of
https://github.com/python/cpython.git
synced 2025-10-13 18:33:34 +00:00
Speed-up lazy heapq import in collections (gh-127538)
This commit is contained in:
parent
bfb0788bfc
commit
dffb90911a
1 changed files with 6 additions and 1 deletions
|
@ -59,6 +59,8 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
heapq = None # Lazily imported
|
||||
|
||||
|
||||
################################################################################
|
||||
### OrderedDict
|
||||
|
@ -633,7 +635,10 @@ class Counter(dict):
|
|||
return sorted(self.items(), key=_itemgetter(1), reverse=True)
|
||||
|
||||
# Lazy import to speedup Python startup time
|
||||
import heapq
|
||||
global heapq
|
||||
if heapq is None:
|
||||
import heapq
|
||||
|
||||
return heapq.nlargest(n, self.items(), key=_itemgetter(1))
|
||||
|
||||
def elements(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue