Use _PyObject_CallMethodIdObjArgs()

Issue #28915: Replace _PyObject_CallMethodId() with
_PyObject_CallMethodIdObjArgs() when the format string only use the format 'O'
for objects, like "(O)".

_PyObject_CallMethodIdObjArgs() avoids the code to parse a format string and
avoids the creation of a temporary tuple.
This commit is contained in:
Victor Stinner 2016-12-09 00:36:19 +01:00
parent 4c38154a43
commit 7e42541d08
3 changed files with 5 additions and 4 deletions

View File

@ -2435,7 +2435,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
}
finally:
res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
Py_DECREF(saved_state);
if (res == NULL)
return NULL;
@ -2449,7 +2449,7 @@ fail:
if (saved_state) {
PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, "(O)", saved_state);
res = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_setstate, saved_state, NULL);
_PyErr_ChainExceptions(type, value, traceback);
Py_DECREF(saved_state);
Py_XDECREF(res);

View File

@ -804,7 +804,8 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *args)
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &def))
return NULL;
return _PyObject_CallMethodId(pp->mapping, &PyId_get, "(OO)", key, def);
return _PyObject_CallMethodIdObjArgs(pp->mapping, &PyId_get,
key, def, NULL);
}
static PyObject *

View File

@ -130,7 +130,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o)
buffer = _PyObject_GetAttrId(outf, &PyId_buffer);
if (buffer) {
result = _PyObject_CallMethodId(buffer, &PyId_write, "(O)", encoded);
result = _PyObject_CallMethodIdObjArgs(buffer, &PyId_write, encoded, NULL);
Py_DECREF(buffer);
Py_DECREF(encoded);
if (result == NULL)