[Python-checkins] cpython: Minor optimization -- factor a constant expression out of the inner-loop.

raymond.hettinger python-checkins at python.org
Fri Mar 18 23:09:35 CET 2011


http://hg.python.org/cpython/rev/cfcff2683c71
changeset:   68670:cfcff2683c71
user:        Raymond Hettinger <python at rcn.com>
date:        Fri Mar 18 15:09:10 2011 -0700
summary:
  Minor optimization -- factor a constant expression out of the inner-loop.

files:
  Lib/functools.py

diff --git a/Lib/functools.py b/Lib/functools.py
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -140,7 +140,7 @@
                 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 @@
                 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 @@
                 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]

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list