]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #26802: Optimized calling a function with *args only positional arguments.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 19 Apr 2016 20:37:17 +0000 (23:37 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 19 Apr 2016 20:37:17 +0000 (23:37 +0300)
Patch by Joe Jevnik.

Python/ceval.c

index d69b8d6cc6d92da2b247b16d1c9e02061ef492b0..88dc1139eb09a3fdd7fb560db7d53fff70dd911b 100644 (file)
@@ -4890,6 +4890,21 @@ update_star_args(int nstack, int nstar, PyObject *stararg,
 {
     PyObject *callargs, *w;
 
+    if (!nstack) {
+        if (!stararg) {
+            /* There are no positional arguments on the stack and there is no
+               sequence to be unpacked. */
+            return PyTuple_New(0);
+        }
+        if (PyTuple_CheckExact(stararg)) {
+            /* No arguments are passed on the stack and the sequence is not a
+               tuple subclass so we can just pass the stararg tuple directly
+               to the function. */
+            Py_INCREF(stararg);
+            return stararg;
+        }
+    }
+
     callargs = PyTuple_New(nstack + nstar);
     if (callargs == NULL) {
         return NULL;