[Python-checkins] r84439 - in python/branches/py3k/Lib: collections.py functools.py
raymond.hettinger
python-checkins at python.org
Thu Sep 2 21:56:28 CEST 2010
Author: raymond.hettinger
Date: Thu Sep 2 21:56:28 2010
New Revision: 84439
Log:
Better method name. Tighten inner-loop with bound methods.
Modified:
python/branches/py3k/Lib/collections.py
python/branches/py3k/Lib/functools.py
Modified: python/branches/py3k/Lib/collections.py
==============================================================================
--- python/branches/py3k/Lib/collections.py (original)
+++ python/branches/py3k/Lib/collections.py Thu Sep 2 21:56:28 2010
@@ -173,7 +173,7 @@
def __del__(self):
self.clear() # eliminate cyclical references
- def _move_to_end(self, key, PREV=0, NEXT=1):
+ def _renew(self, key, PREV=0, NEXT=1):
'Fast version of self[key]=self.pop(key). Private method for internal use.'
link = self.__map[key]
link_prev = link[PREV]
Modified: python/branches/py3k/Lib/functools.py
==============================================================================
--- python/branches/py3k/Lib/functools.py (original)
+++ python/branches/py3k/Lib/functools.py Thu Sep 2 21:56:28 2010
@@ -128,6 +128,7 @@
def decorating_function(user_function, tuple=tuple, sorted=sorted,
len=len, KeyError=KeyError):
cache = OrderedDict() # ordered least recent to most recent
+ cache_popitem, cache_renew = cache.popitem, cache._renew
kwd_mark = object() # separate positional and keyword args
lock = Lock()
@@ -139,7 +140,7 @@
try:
with lock:
result = cache[key]
- cache._move_to_end(key) # record recent use of this key
+ cache_renew(key) # record recent use of this key
wrapper.hits += 1
except KeyError:
result = user_function(*args, **kwds)
@@ -147,7 +148,7 @@
cache[key] = result # record recent use of this key
wrapper.misses += 1
if len(cache) > maxsize:
- cache.popitem(0) # purge least recently used cache entry
+ cache_popitem(0) # purge least recently used cache entry
return result
def clear():
More information about the Python-checkins
mailing list