[Python-checkins] cpython (3.3): Sync-up with 3.4 to make maintenance easier.

raymond.hettinger python-checkins at python.org
Sat Mar 9 08:05:29 CET 2013


http://hg.python.org/cpython/rev/a9fa8a18d18d
changeset: 82560:a9fa8a18d18d
branch: 3.3
parent: 82558:1af9f7df3a96
user: Raymond Hettinger <python at rcn.com>
date: Fri Mar 08 23:01:07 2013 -0800
summary:
 Sync-up with 3.4 to make maintenance easier.
files:
 Lib/functools.py | 16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/Lib/functools.py b/Lib/functools.py
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -222,7 +222,7 @@
 def decorating_function(user_function):
 
 cache = {}
- hits = misses = currsize = 0
+ hits = misses = 0
 full = False
 cache_get = cache.get # bound method to lookup a key or return None
 lock = RLock() # because linkedlist updates aren't threadsafe
@@ -242,7 +242,7 @@
 
 def wrapper(*args, **kwds):
 # Simple caching without ordering or size limit
- nonlocal hits, misses, currsize
+ nonlocal hits, misses
 key = make_key(args, kwds, typed)
 result = cache_get(key, sentinel)
 if result is not sentinel:
@@ -251,14 +251,13 @@
 result = user_function(*args, **kwds)
 cache[key] = result
 misses += 1
- currsize += 1
 return result
 
 else:
 
 def wrapper(*args, **kwds):
 # Size limited caching that tracks accesses by recency
- nonlocal root, hits, misses, currsize, full
+ nonlocal root, hits, misses, full
 key = make_key(args, kwds, typed)
 with lock:
 link = cache_get(key)
@@ -307,23 +306,22 @@
 last = root[PREV]
 link = [last, root, key, result]
 last[NEXT] = root[PREV] = cache[key] = link
- currsize += 1
- full = (currsize >= maxsize)
+ full = (len(cache) >= maxsize)
 misses += 1
 return result
 
 def cache_info():
 """Report cache statistics"""
 with lock:
- return _CacheInfo(hits, misses, maxsize, currsize)
+ return _CacheInfo(hits, misses, maxsize, len(cache))
 
 def cache_clear():
 """Clear the cache and cache statistics"""
- nonlocal hits, misses, currsize, full
+ nonlocal hits, misses, full
 with lock:
 cache.clear()
 root[:] = [root, root, None, None]
- hits = misses = currsize = 0
+ hits = misses = 0
 full = False
 
 wrapper.cache_info = cache_info
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /