Skip to content

Commit f4de184

Browse files
authored
gh-143825: Micro-optimizations to _make_key. (gh-143844)
1 parent 499706b commit f4de184

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Lib/functools.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def _unwrap_partialmethod(func):
517517
### LRU Cache function decorator
518518
################################################################################
519519

520-
_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
520+
_CacheInfo = namedtuple("CacheInfo", ("hits", "misses", "maxsize", "currsize"))
521521

522522
def _make_key(args, kwds, typed,
523523
kwd_mark = (object(),),
@@ -539,13 +539,15 @@ def _make_key(args, kwds, typed,
539539
# distinct call from f(y=2, x=1) which will be cached separately.
540540
key = args
541541
if kwds:
542+
key = list(key)
542543
key += kwd_mark
543544
for item in kwds.items():
544545
key += item
546+
key = tuple(key)
545547
if typed:
546-
key += tuple(type(v) for v in args)
548+
key += tuple([type(v) for v in args])
547549
if kwds:
548-
key += tuple(type(v) for v in kwds.values())
550+
key += tuple([type(v) for v in kwds.values()])
549551
elif len(key) == 1 and type(key[0]) in fasttypes:
550552
return key[0]
551553
return key

0 commit comments

Comments
 (0)