MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _make_key

Function _make_key

tools/python-3.11.9-amd64/Lib/functools.py:448–477  ·  view source on GitHub ↗

Make a cache key from optionally typed positional and keyword arguments The key is constructed in a way that is flat as possible rather than as a nested structure that would take more memory. If there is only a single argument and its data type is known to cache its hash valu

(args, kwds, typed,
             kwd_mark = (object(),),
             fasttypes = {int, str},
             tuple=tuple, type=type, len=len)

Source from the content-addressed store, hash-verified

446 return self.hashvalue
447
448def _make_key(args, kwds, typed,
449 kwd_mark = (object(),),
450 fasttypes = {int, str},
451 tuple=tuple, type=type, len=len):
452 """Make a cache key from optionally typed positional and keyword arguments
453
454 The key is constructed in a way that is flat as possible rather than
455 as a nested structure that would take more memory.
456
457 If there is only a single argument and its data type is known to cache
458 its hash value, then that argument is returned without a wrapper. This
459 saves space and improves lookup speed.
460
461 """
462 # All of code below relies on kwds preserving the order input by the user.
463 # Formerly, we sorted() the kwds before looping. The new way is *much*
464 # faster; however, it means that f(x=1, y=2) will now be treated as a
465 # distinct call from f(y=2, x=1) which will be cached separately.
466 key = args
467 if kwds:
468 key += kwd_mark
469 for item in kwds.items():
470 key += item
471 if typed:
472 key += tuple(type(v) for v in args)
473 if kwds:
474 key += tuple(type(v) for v in kwds.values())
475 elif len(key) == 1 and type(key[0]) in fasttypes:
476 return key[0]
477 return _HashedSeq(key)
478
479def lru_cache(maxsize=128, typed=False):
480 """Least-recently-used cache decorator.

Callers

nothing calls this directly

Calls 5

tupleClass · 0.85
_HashedSeqClass · 0.85
typeClass · 0.50
itemsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected