[Python-checkins] cpython: call_method() and call_maybe() now use fast call
victor.stinner
python-checkins at python.org
Fri Aug 19 12:53:53 EDT 2016
https://hg.python.org/cpython/rev/8e085070ab28
changeset: 102773:8e085070ab28
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Aug 19 18:05:37 2016 +0200
summary:
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.
files:
Objects/typeobject.c | 54 +++++++++++++++++--------------
1 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1424,7 +1424,7 @@
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 @@
}
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;
- }
-
- assert(PyTuple_Check(args));
- retval = PyObject_Call(func, args, NULL);
-
- Py_DECREF(args);
+ retval = _PyObject_FastCall(func, NULL, 0, NULL);
+ }
+
Py_DECREF(func);
return retval;
@@ -1461,7 +1464,7 @@
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 @@
}
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;
- }
-
- assert(PyTuple_Check(args));
- retval = PyObject_Call(func, args, NULL);
-
- Py_DECREF(args);
+ retval = _PyObject_FastCall(func, NULL, 0, NULL);
+ }
+
Py_DECREF(func);
return retval;
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list