summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-08-19 16:05:37 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-08-19 16:05:37 (GMT)
commitf736c261a2094eee1529c98786c612904c067540 (patch)
tree7f00ff1205505e699131dea5f482345802df7e91 /Objects/typeobject.c
parent94463c980ec8b3f54bd223036ec0363ff4266362 (diff)
downloadcpython-f736c261a2094eee1529c98786c612904c067540.zip
cpython-f736c261a2094eee1529c98786c612904c067540.tar.gz
cpython-f736c261a2094eee1529c98786c612904c067540.tar.bz2
call_method() and call_maybe() now use fast call
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.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 10ced8b..4f01da0 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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;