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

Skip to content

Commit 32e2ff5

Browse files
committed
merge
2 parents 6c2078d + f2c17a9 commit 32e2ff5

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Lib/functools.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,23 @@ def wrapper(*args, **kwds):
291291
# computed result and update the count of misses.
292292
pass
293293
elif full:
294-
# use root to store the new key and result
295-
root[KEY] = key
296-
root[RESULT] = result
297-
cache[key] = root
294+
# use the old root to store the new key and result
295+
oldroot = root
296+
oldroot[KEY] = key
297+
oldroot[RESULT] = result
298298
# empty the oldest link and make it the new root
299-
root = root[NEXT]
300-
del cache[root[KEY]]
299+
root = oldroot[NEXT]
300+
oldkey = root[KEY]
301+
oldvalue = root[RESULT]
301302
root[KEY] = root[RESULT] = None
303+
# now update the cache dictionary for the new links
304+
del cache[oldkey]
305+
cache[key] = oldroot
302306
else:
303307
# put result in a new link at the front of the queue
304308
last = root[PREV]
305309
link = [last, root, key, result]
306-
cache[key] = last[NEXT] = root[PREV] = link
310+
last[NEXT] = root[PREV] = cache[key] = link
307311
full = (len(cache) == maxsize)
308312
misses += 1
309313
return result

0 commit comments

Comments
 (0)