summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2017-01-09 02:22:24 (GMT)
committerRaymond Hettinger <python@rcn.com>2017-01-09 02:22:24 (GMT)
commit19c7238560644accd00c6ccd4497ef40142a06c2 (patch)
treec6475a144e4d571e8f79e8a9f5a1ba15818c9054 /Lib
parent4ee39141e84c511e389080fa3163be043718ea14 (diff)
downloadcpython-19c7238560644accd00c6ccd4497ef40142a06c2.zip
cpython-19c7238560644accd00c6ccd4497ef40142a06c2.tar.gz
cpython-19c7238560644accd00c6ccd4497ef40142a06c2.tar.bz2
Sync-up with 3.7 by backporting minor lru_cache code beautification
Diffstat (limited to 'Lib')
-rw-r--r--Lib/functools.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 030c91b..89f2cf4 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -492,6 +492,7 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
hits = misses = 0
full = False
cache_get = cache.get # bound method to lookup a key or return None
+ cache_len = cache.__len__ # get cache size without calling len()
lock = RLock() # because linkedlist updates aren't threadsafe
root = [] # root of the circular doubly linked list
root[:] = [root, root, None, None] # initialize by pointing to self
@@ -573,16 +574,16 @@ def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
last = root[PREV]
link = [last, root, key, result]
last[NEXT] = root[PREV] = cache[key] = link
- # Use the __len__() method instead of the len() function
+ # Use the cache_len bound method instead of the len() function
# which could potentially be wrapped in an lru_cache itself.
- full = (cache.__len__() >= maxsize)
+ full = (cache_len() >= maxsize)
misses += 1
return result
def cache_info():
"""Report cache statistics"""
with lock:
- return _CacheInfo(hits, misses, maxsize, cache.__len__())
+ return _CacheInfo(hits, misses, maxsize, cache_len())
def cache_clear():
"""Clear the cache and cache statistics"""