From 9d60b94427f42b3f543e398205113a1b18b43598 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 8 Jan 2017 19:34:28 -0800 Subject: [PATCH] Sync-up lru_cache() C code with space saving feature in the Python version. --- Modules/_functoolsmodule.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c index 62b45e98cb..bc34c215b4 100644 --- a/Modules/_functoolsmodule.c +++ b/Modules/_functoolsmodule.c @@ -709,6 +709,12 @@ lru_cache_make_key(PyObject *args, PyObject *kwds, int typed) /* short path, key will match args anyway, which is a tuple */ if (!typed && !kwds) { + if (PyTuple_GET_SIZE(args) == 1) { + /* Save space and improve speed by unwrapping 1-tuples */ + key = PyTuple_GET_ITEM(args, 0); + Py_INCREF(key); + return key; + } Py_INCREF(args); return args; } -- 2.40.0