Skip to content

Commit 822c426

Browse files
committed
Sync-up lru_cache() C code with space saving feature in the Python version.
1 parent 4b2917d commit 822c426

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Modules/_functoolsmodule.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,12 @@ lru_cache_make_key(PyObject *args, PyObject *kwds, int typed)
709709

710710
/* short path, key will match args anyway, which is a tuple */
711711
if (!typed && !kwds) {
712+
if (PyTuple_GET_SIZE(args) == 1) {
713+
/* Save space and improve speed by unwrapping 1-tuples */
714+
key = PyTuple_GET_ITEM(args, 0);
715+
Py_INCREF(key);
716+
return key;
717+
}
712718
Py_INCREF(args);
713719
return args;
714720
}

0 commit comments

Comments
 (0)