Skip to content

Commit d7498af

Browse files
committed
Avoid bound method allocation in PyFile_WriteObject
1 parent 75d96f8 commit d7498af

1 file changed

Lines changed: 3 additions & 13 deletions

File tree

‎Objects/fileobject.c‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,17 @@ PyFile_GetLine(PyObject *f, int n)
106106
int
107107
PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
108108
{
109-
PyObject *writer, *value, *result;
110-
111109
if (f == NULL) {
112110
PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
113111
return -1;
114112
}
115-
writer = PyObject_GetAttr(f, &_Py_ID(write));
116-
if (writer == NULL)
117-
return -1;
118-
if (flags & Py_PRINT_RAW) {
119-
value = PyObject_Str(v);
120-
}
121-
else
122-
value = PyObject_Repr(v);
113+
114+
PyObject *value = (flags & Py_PRINT_RAW) ? PyObject_Str(v) : PyObject_Repr(v);
123115
if (value == NULL) {
124-
Py_DECREF(writer);
125116
return -1;
126117
}
127-
result = PyObject_CallOneArg(writer, value);
118+
PyObject *result = PyObject_CallMethodOneArg(f, &_Py_ID(write), value);
128119
Py_DECREF(value);
129-
Py_DECREF(writer);
130120
if (result == NULL)
131121
return -1;
132122
Py_DECREF(result);

0 commit comments

Comments
 (0)