From 0f7b0b397e12514ee213bc727c9939b66585cbe2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 14 Mar 2017 21:37:20 +0100 Subject: bpo-29735: Optimize partial_call(): avoid tuple (#516) * Add _PyObject_HasFastCall() * partial_call() now avoids temporary tuple to pass positional arguments if the callable supports the FASTCALL calling convention for positional arguments. * Fix also a performance regression in partial_call() if the callable doesn't support FASTCALL. --- Objects/call.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Objects/call.c') diff --git a/Objects/call.c b/Objects/call.c index f1b14080ff..dd022ec6e8 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -2,6 +2,22 @@ #include "frameobject.h" +int +_PyObject_HasFastCall(PyObject *callable) +{ + if (PyFunction_Check(callable)) { + return 1; + } + else if (PyCFunction_Check(callable)) { + return !(PyCFunction_GET_FLAGS(callable) & METH_VARARGS); + } + else { + assert (PyCallable_Check(callable)); + return 0; + } +} + + static PyObject * null_error(void) { -- cgit v1.2.1