From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 13 May 2025 13:58:25 +0000 (+0200) Subject: [3.14] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969) (#133971) X-Git-Tag: v3.14.0b2~160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5632e93f467564a1d09bd6d38caef6c4fa1f047f;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969) (#133971) gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (GH-133969) Don't call PyObject_Str() if the input type is str. (cherry picked from commit fe9f6e829a535747b1e06d9bfda033a9a47165ed) Co-authored-by: Victor Stinner --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4e1aafb91fc8..9b8e3bb5462d 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -13954,7 +13954,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); }