summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-03-04 08:54:45 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-03-04 08:54:45 (GMT)
commit32e2ff5dc5f0c78c943e958c52feb0424ae94a1b (patch)
tree0dee2828c925bed56019ff22eecf45dc61efc15d /Lib/functools.py
parent6c2078d545c5e0bcc5c393d30e670e8e4f9bb3e3 (diff)
parentf2c17a9276e5793b4a0e9e84a338a1c874ddd01c (diff)
downloadcpython-32e2ff5dc5f0c78c943e958c52feb0424ae94a1b.zip
cpython-32e2ff5dc5f0c78c943e958c52feb0424ae94a1b.tar.gz
cpython-32e2ff5dc5f0c78c943e958c52feb0424ae94a1b.tar.bz2
merge
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index a019268..02bff42 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -291,19 +291,23 @@ def lru_cache(maxsize=128, typed=False):
# computed result and update the count of misses.
pass
elif full:
- # use root to store the new key and result
- root[KEY] = key
- root[RESULT] = result
- cache[key] = root
+ # use the old root to store the new key and result
+ oldroot = root
+ oldroot[KEY] = key
+ oldroot[RESULT] = result
# empty the oldest link and make it the new root
- root = root[NEXT]
- del cache[root[KEY]]
+ root = oldroot[NEXT]
+ oldkey = root[KEY]
+ oldvalue = root[RESULT]
root[KEY] = root[RESULT] = None
+ # now update the cache dictionary for the new links
+ del cache[oldkey]
+ cache[key] = oldroot
else:
# put result in a new link at the front of the queue
last = root[PREV]
link = [last, root, key, result]
- cache[key] = last[NEXT] = root[PREV] = link
+ last[NEXT] = root[PREV] = cache[key] = link
full = (len(cache) == maxsize)
misses += 1
return result