]> granicus.if.org Git - python/commitdiff
Sync-up lru_cache() C code with space saving feature in the Python version.
authorRaymond Hettinger <python@rcn.com>
Mon, 9 Jan 2017 03:34:28 +0000 (19:34 -0800)
committerRaymond Hettinger <python@rcn.com>
Mon, 9 Jan 2017 03:34:28 +0000 (19:34 -0800)
Modules/_functoolsmodule.c

index 62b45e98cb831aba1d7c0a03af37b2ace4e98d7d..bc34c215b4382c5a3f3071f2e735da2ce8c7b681 100644 (file)
@@ -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;
     }