From 7e4c168385b5f723dbeb340abe51f7b99399e1c7 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 18 Mar 2011 15:09:10 -0700 Subject: Minor optimization -- factor a constant expression out of the inner-loop. --- Lib/functools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/functools.py b/Lib/functools.py index 03de69a..fdc9c79 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -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] -- cgit v0.12