summaryrefslogtreecommitdiffstats
path: root/Lib/functools.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2012-04-29 21:55:27 (GMT)
committerRaymond Hettinger <python@rcn.com>2012-04-29 21:55:27 (GMT)
commit9f0ab9f5649b9b6ee54a023e83417f244b4665a0 (patch)
tree5a1f308b48e8f96d3a6c23c452abd702735ba62f /Lib/functools.py
parent678e7f3be658df7e1bd06bb0c37d820143f15eca (diff)
downloadcpython-9f0ab9f5649b9b6ee54a023e83417f244b4665a0.zip
cpython-9f0ab9f5649b9b6ee54a023e83417f244b4665a0.tar.gz
cpython-9f0ab9f5649b9b6ee54a023e83417f244b4665a0.tar.bz2
Factor out shared variables.
Diffstat (limited to 'Lib/functools.py')
-rw-r--r--Lib/functools.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index 1e7795f..af0864f 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -167,18 +167,20 @@ def lru_cache(maxsize=100, typed=False):
# The internals of the lru_cache are encapsulated for thread safety and
# to allow the implementation to change (including a possible C version).
+ # Constants shared by all lru cache instances:
+ kwd_mark = (object(),) # separate positional and keyword args
+ sentinel = object() # unique object used to signal cache misses
+ _len = len # localize the global len() function
+ PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields
+
def decorating_function(user_function):
cache = {}
hits = misses = 0
- kwd_mark = (object(),) # separate positional and keyword args
cache_get = cache.get # bound method to lookup a key or return None
- sentinel = object() # unique object used with cache_get
- _len = len # localize the global len() function
lock = Lock() # because linkedlist updates aren't threadsafe
root = [] # root of the circular doubly linked list
root[:] = [root, root, None, None] # initialize by pointing to self
- PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields
def make_key(args, kwds, typed, tuple=tuple, sorted=sorted, type=type):
# build a cache key from positional and keyword args