From: Victor Stinner Date: Tue, 13 May 2025 13:31:41 +0000 (+0200) Subject: gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (#133969) X-Git-Tag: v3.15.0a1~1736 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fe9f6e829a535747b1e06d9bfda033a9a47165ed;p=thirdparty%2FPython%2Fcpython.git gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (#133969) Don't call PyObject_Str() if the input type is str. --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index cd26494ad8f1..aa94fb91e65f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13929,7 +13929,12 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str) int PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj) { - if (Py_TYPE(obj) == &PyLong_Type) { + PyTypeObject *type = Py_TYPE(obj); + if (type == &PyUnicode_Type) { + return _PyUnicodeWriter_WriteStr((_PyUnicodeWriter*)writer, obj); + } + + if (type == &PyLong_Type) { return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0); }