Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d8d6010

Browse files
committed
Sync-up with 3.4 to make maintenance easier.
1 parent f96b2b0 commit d8d6010

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

Lib/functools.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def lru_cache(maxsize=128, typed=False):
222222
def decorating_function(user_function):
223223

224224
cache = {}
225-
hits = misses = currsize = 0
225+
hits = misses = 0
226226
full = False
227227
cache_get = cache.get # bound method to lookup a key or return None
228228
lock = RLock() # because linkedlist updates aren't threadsafe
@@ -242,7 +242,7 @@ def wrapper(*args, **kwds):
242242

243243
def wrapper(*args, **kwds):
244244
# Simple caching without ordering or size limit
245-
nonlocal hits, misses, currsize
245+
nonlocal hits, misses
246246
key = make_key(args, kwds, typed)
247247
result = cache_get(key, sentinel)
248248
if result is not sentinel:
@@ -251,14 +251,13 @@ def wrapper(*args, **kwds):
251251
result = user_function(*args, **kwds)
252252
cache[key] = result
253253
misses += 1
254-
currsize += 1
255254
return result
256255

257256
else:
258257

259258
def wrapper(*args, **kwds):
260259
# Size limited caching that tracks accesses by recency
261-
nonlocal root, hits, misses, currsize, full
260+
nonlocal root, hits, misses, full
262261
key = make_key(args, kwds, typed)
263262
with lock:
264263
link = cache_get(key)
@@ -307,23 +306,22 @@ def wrapper(*args, **kwds):
307306
last = root[PREV]
308307
link = [last, root, key, result]
309308
last[NEXT] = root[PREV] = cache[key] = link
310-
currsize += 1
311-
full = (currsize >= maxsize)
309+
full = (len(cache) >= maxsize)
312310
misses += 1
313311
return result
314312

315313
def cache_info():
316314
"""Report cache statistics"""
317315
with lock:
318-
return _CacheInfo(hits, misses, maxsize, currsize)
316+
return _CacheInfo(hits, misses, maxsize, len(cache))
319317

320318
def cache_clear():
321319
"""Clear the cache and cache statistics"""
322-
nonlocal hits, misses, currsize, full
320+
nonlocal hits, misses, full
323321
with lock:
324322
cache.clear()
325323
root[:] = [root, root, None, None]
326-
hits = misses = currsize = 0
324+
hits = misses = 0
327325
full = False
328326

329327
wrapper.cache_info = cache_info

0 commit comments

Comments
 (0)