[Python-checkins] cpython: Issue #28991: Address comment that the __len__ call looked unattractive
raymond.hettinger
python-checkins at python.org
Fri Dec 16 18:01:04 EST 2016
https://hg.python.org/cpython/rev/5ec5bfcf0089
changeset: 105691:5ec5bfcf0089
user: Raymond Hettinger <python at rcn.com>
date: Fri Dec 16 14:59:37 2016 -0800
summary:
Issue #28991: Address comment that the __len__ call looked unattractive
files:
Lib/functools.py | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/Lib/functools.py b/Lib/functools.py
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -493,6 +493,7 @@
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
@@ -574,16 +575,16 @@
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"""
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list