summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2017-01-09 03:34:28 (GMT)
committerRaymond Hettinger <python@rcn.com>2017-01-09 03:34:28 (GMT)
commit9d60b94427f42b3f543e398205113a1b18b43598 (patch)
tree36e6a35d42ad360c80be9ccc11fc5e9e390430f6 /Modules
parent44844ccc066f44bc894db0ecbfb96fac0e2a25eb (diff)
downloadcpython-9d60b94427f42b3f543e398205113a1b18b43598.zip
cpython-9d60b94427f42b3f543e398205113a1b18b43598.tar.gz
cpython-9d60b94427f42b3f543e398205113a1b18b43598.tar.bz2
Sync-up lru_cache() C code with space saving feature in the Python version.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_functoolsmodule.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 62b45e9..bc34c21 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;
}