]> granicus.if.org Git - python/commitdiff
Minor optimization -- factor a constant expression out of the inner-loop.
authorRaymond Hettinger <python@rcn.com>
Fri, 18 Mar 2011 22:09:10 +0000 (15:09 -0700)
committerRaymond Hettinger <python@rcn.com>
Fri, 18 Mar 2011 22:09:10 +0000 (15:09 -0700)
Lib/functools.py

index 03de69ae161ad54e42d8ad3d5e8958237b44aca8..fdc9c79098bec1ebcb170d94ca8ea60ae08af945 100644 (file)
@@ -140,7 +140,7 @@ def lru_cache(maxsize=100):
                 tuple=tuple, sorted=sorted, len=len, KeyError=KeyError):
 
         hits = misses = 0
-        kwd_mark = object()             # separates positional and keyword args
+        kwd_mark = (object(),)          # separates positional and keyword args
         lock = Lock()                   # needed because ordereddicts aren't threadsafe
 
         if maxsize is None:
@@ -151,7 +151,7 @@ def lru_cache(maxsize=100):
                 nonlocal hits, misses
                 key = args
                 if kwds:
-                    key += (kwd_mark,) + tuple(sorted(kwds.items()))
+                    key += kwd_mark + tuple(sorted(kwds.items()))
                 try:
                     result = cache[key]
                     hits += 1
@@ -170,7 +170,7 @@ def lru_cache(maxsize=100):
                 nonlocal hits, misses
                 key = args
                 if kwds:
-                    key += (kwd_mark,) + tuple(sorted(kwds.items()))
+                    key += kwd_mark + tuple(sorted(kwds.items()))
                 try:
                     with lock:
                         result = cache[key]