diff options
author | Raymond Hettinger <python@rcn.com> | 2013-02-17 08:08:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-02-17 08:08:45 (GMT) |
commit | 832eddeafbf6265b8d88b468fed9f193459b5678 (patch) | |
tree | 2ba1306d33212904d425898c0ccfa450f5258e86 /Lib/functools.py | |
parent | 5df9f82547dd9b567ffe2976f8235987a58534a7 (diff) | |
download | cpython-832eddeafbf6265b8d88b468fed9f193459b5678.zip cpython-832eddeafbf6265b8d88b468fed9f193459b5678.tar.gz cpython-832eddeafbf6265b8d88b468fed9f193459b5678.tar.bz2 |
Eliminate unnecessary variable.
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index 60d2cf1..2647f2d 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -228,9 +228,8 @@ def lru_cache(maxsize=128, typed=False): PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields def decorating_function(user_function): - cache = {} - hits = misses = currsize = 0 + hits = misses = 0 full = False cache_get = cache.get # bound method to lookup a key or return None lock = Lock() # because linkedlist updates aren't threadsafe @@ -250,7 +249,7 @@ def lru_cache(maxsize=128, typed=False): def wrapper(*args, **kwds): # simple caching without ordering or size limit - nonlocal hits, misses, currsize + nonlocal hits, misses key = make_key(args, kwds, typed) result = cache_get(key, sentinel) if result is not sentinel: @@ -259,14 +258,13 @@ def lru_cache(maxsize=128, typed=False): result = user_function(*args, **kwds) cache[key] = result misses += 1 - currsize += 1 return result else: def wrapper(*args, **kwds): # size limited caching that tracks accesses by recency - nonlocal root, hits, misses, currsize, full + nonlocal root, hits, misses, full key = make_key(args, kwds, typed) with lock: link = cache_get(key) @@ -303,23 +301,22 @@ def lru_cache(maxsize=128, typed=False): last = root[PREV] link = [last, root, key, result] cache[key] = last[NEXT] = root[PREV] = link - currsize += 1 - full = (currsize == maxsize) + full = (len(cache) == maxsize) misses += 1 return result def cache_info(): """Report cache statistics""" with lock: - return _CacheInfo(hits, misses, maxsize, currsize) + return _CacheInfo(hits, misses, maxsize, len(cache)) def cache_clear(): """Clear the cache and cache statistics""" - nonlocal hits, misses, currsize, full + nonlocal hits, misses, full with lock: cache.clear() root[:] = [root, root, None, None] - hits = misses = currsize = 0 + hits = misses = 0 full = False wrapper.cache_info = cache_info |