]> granicus.if.org Git - python/commitdiff
call_method() and call_maybe() now use fast call
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:05:37 +0000 (18:05 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:05:37 +0000 (18:05 +0200)
Issue #27128. The call_method() and call_maybe() functions of typeobject.c now
use fast call for empty format string to avoid the creation of a temporary
empty tuple.

Objects/typeobject.c

index 10ced8b064f9967b5e3c4a7f636aaebbd5a63864..4f01da01b9567db70e215aab4d162e03fd8b186d 100644 (file)
@@ -1424,7 +1424,7 @@ static PyObject *
 call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
 {
     va_list va;
-    PyObject *args, *func = 0, *retval;
+    PyObject *func = NULL, *retval;
 
     func = lookup_maybe(o, nameid);
     if (func == NULL) {
@@ -1434,22 +1434,25 @@ call_method(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
     }
 
     if (format && *format) {
+        PyObject *args;
+
         va_start(va, format);
         args = Py_VaBuildValue(format, va);
         va_end(va);
+
+        if (args == NULL) {
+            Py_DECREF(func);
+            return NULL;
+        }
+        assert(PyTuple_Check(args));
+
+        retval = PyObject_Call(func, args, NULL);
+        Py_DECREF(args);
     }
     else {
-        args = PyTuple_New(0);
-    }
-    if (args == NULL) {
-        Py_DECREF(func);
-        return NULL;
+        retval = _PyObject_FastCall(func, NULL, 0, NULL);
     }
 
-    assert(PyTuple_Check(args));
-    retval = PyObject_Call(func, args, NULL);
-
-    Py_DECREF(args);
     Py_DECREF(func);
 
     return retval;
@@ -1461,7 +1464,7 @@ static PyObject *
 call_maybe(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
 {
     va_list va;
-    PyObject *args, *func = 0, *retval;
+    PyObject *func = NULL, *retval;
 
     func = lookup_maybe(o, nameid);
     if (func == NULL) {
@@ -1471,22 +1474,25 @@ call_maybe(PyObject *o, _Py_Identifier *nameid, const char *format, ...)
     }
 
     if (format && *format) {
+        PyObject *args;
+
         va_start(va, format);
         args = Py_VaBuildValue(format, va);
         va_end(va);
+
+        if (args == NULL) {
+            Py_DECREF(func);
+            return NULL;
+        }
+        assert(PyTuple_Check(args));
+
+        retval = PyObject_Call(func, args, NULL);
+        Py_DECREF(args);
     }
     else {
-        args = PyTuple_New(0);
-    }
-    if (args == NULL) {
-        Py_DECREF(func);
-        return NULL;
+        retval = _PyObject_FastCall(func, NULL, 0, NULL);
     }
 
-    assert(PyTuple_Check(args));
-    retval = PyObject_Call(func, args, NULL);
-
-    Py_DECREF(args);
     Py_DECREF(func);
 
     return retval;