[Python-checkins] cpython: Sync-up lru_cache() C code with space saving feature in the Python version.

raymond.hettinger python-checkins at python.org
Sun Jan 8 22:34:38 EST 2017


https://hg.python.org/cpython/rev/ea064ff3c10f
changeset:   106052:ea064ff3c10f
parent:      106050:bc6abb780844
user:        Raymond Hettinger <python at rcn.com>
date:        Sun Jan 08 19:34:28 2017 -0800
summary:
  Sync-up lru_cache() C code with space saving feature in the Python version.

files:
  Modules/_functoolsmodule.c |  6 ++++++
  1 files changed, 6 insertions(+), 0 deletions(-)


diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -709,6 +709,12 @@
 
     /* 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;
     }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list