Use _PyObject_CallMethodIdObjArgs() in _io
Issue #28915: Replace _PyObject_CallMethodId() with _PyObject_CallMethodIdObjArgs() when the format string was only made of "O" formats, PyObject* arguments. _PyObject_CallMethodIdObjArgs() avoids the creation of a temporary tuple and doesn't have to parse a format string.
This commit is contained in:
parent
20401deae2
commit
61bdb0d319
|
@ -454,7 +454,8 @@ buffered_dealloc_warn(buffered *self, PyObject *source)
|
||||||
{
|
{
|
||||||
if (self->ok && self->raw) {
|
if (self->ok && self->raw) {
|
||||||
PyObject *r;
|
PyObject *r;
|
||||||
r = _PyObject_CallMethodId(self->raw, &PyId__dealloc_warn, "O", source);
|
r = _PyObject_CallMethodIdObjArgs(self->raw, &PyId__dealloc_warn,
|
||||||
|
source, NULL);
|
||||||
if (r)
|
if (r)
|
||||||
Py_DECREF(r);
|
Py_DECREF(r);
|
||||||
else
|
else
|
||||||
|
|
|
@ -150,8 +150,8 @@ _io_FileIO_close_impl(fileio *self)
|
||||||
PyObject *exc, *val, *tb;
|
PyObject *exc, *val, *tb;
|
||||||
int rc;
|
int rc;
|
||||||
_Py_IDENTIFIER(close);
|
_Py_IDENTIFIER(close);
|
||||||
res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
|
res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
|
||||||
&PyId_close, "O", self);
|
&PyId_close, self, NULL);
|
||||||
if (!self->closefd) {
|
if (!self->closefd) {
|
||||||
self->fd = -1;
|
self->fd = -1;
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -661,7 +661,8 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
|
||||||
to remove the bytecode interpretation overhead, but it could
|
to remove the bytecode interpretation overhead, but it could
|
||||||
probably be removed here. */
|
probably be removed here. */
|
||||||
_Py_IDENTIFIER(extend);
|
_Py_IDENTIFIER(extend);
|
||||||
PyObject *ret = _PyObject_CallMethodId(result, &PyId_extend, "O", self);
|
PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend,
|
||||||
|
self, NULL);
|
||||||
|
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
|
|
|
@ -899,8 +899,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
||||||
PyObject *locale_module = _PyIO_get_locale_module(state);
|
PyObject *locale_module = _PyIO_get_locale_module(state);
|
||||||
if (locale_module == NULL)
|
if (locale_module == NULL)
|
||||||
goto catch_ImportError;
|
goto catch_ImportError;
|
||||||
self->encoding = _PyObject_CallMethodId(
|
self->encoding = _PyObject_CallMethodIdObjArgs(
|
||||||
locale_module, &PyId_getpreferredencoding, "O", Py_False);
|
locale_module, &PyId_getpreferredencoding, Py_False, NULL);
|
||||||
Py_DECREF(locale_module);
|
Py_DECREF(locale_module);
|
||||||
if (self->encoding == NULL) {
|
if (self->encoding == NULL) {
|
||||||
catch_ImportError:
|
catch_ImportError:
|
||||||
|
@ -2644,7 +2644,9 @@ _io_TextIOWrapper_close_impl(textio *self)
|
||||||
else {
|
else {
|
||||||
PyObject *exc = NULL, *val, *tb;
|
PyObject *exc = NULL, *val, *tb;
|
||||||
if (self->finalizing) {
|
if (self->finalizing) {
|
||||||
res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self);
|
res = _PyObject_CallMethodIdObjArgs(self->buffer,
|
||||||
|
&PyId__dealloc_warn,
|
||||||
|
self, NULL);
|
||||||
if (res)
|
if (res)
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
else
|
else
|
||||||
|
|
|
@ -85,7 +85,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) {
|
||||||
Py_CLEAR(decoded);
|
Py_CLEAR(decoded);
|
||||||
return '\0';
|
return '\0';
|
||||||
}
|
}
|
||||||
decoded_upper = PyObject_CallMethod(decoded, "upper", "");
|
decoded_upper = PyObject_CallMethod(decoded, "upper", NULL);
|
||||||
Py_CLEAR(decoded);
|
Py_CLEAR(decoded);
|
||||||
if (!decoded_upper) {
|
if (!decoded_upper) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -181,8 +181,8 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self)
|
||||||
PyObject *exc, *val, *tb;
|
PyObject *exc, *val, *tb;
|
||||||
int rc;
|
int rc;
|
||||||
_Py_IDENTIFIER(close);
|
_Py_IDENTIFIER(close);
|
||||||
res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
|
res = _PyObject_CallMethodIdObjArgs((PyObject*)&PyRawIOBase_Type,
|
||||||
&PyId_close, "O", self);
|
&PyId_close, self, NULL);
|
||||||
if (!self->closehandle) {
|
if (!self->closehandle) {
|
||||||
self->handle = INVALID_HANDLE_VALUE;
|
self->handle = INVALID_HANDLE_VALUE;
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue