Eliminate duplicate link lookup. Minor cleanup.

This commit is contained in:
Raymond Hettinger 2012-03-16 11:21:39 -07:00
parent eb74918685
commit 57b2959d26
1 changed files with 2 additions and 2 deletions

View File

@ -191,11 +191,11 @@ def lru_cache(maxsize=100, typed=False):
key += tuple(map(type, args)) key += tuple(map(type, args))
if kwds: if kwds:
key += tuple(type(v) for k, v in sorted_items) key += tuple(type(v) for k, v in sorted_items)
PREV, NEXT = 0, 1 # names of link fields PREV = 0 # names of link fields
NEXT = 1
with lock: with lock:
link = cache_get(key) link = cache_get(key)
if link is not None: if link is not None:
link = cache[key]
# record recent use of the key by moving it to the front of the list # record recent use of the key by moving it to the front of the list
link_prev, link_next, key, result = link link_prev, link_next, key, result = link
link_prev[NEXT] = link_next link_prev[NEXT] = link_next