https://github.com/python/cpython/commit/fe9f6e829a535747b1e06d9bfda033a9a47165ed commit: fe9f6e829a535747b1e06d9bfda033a9a47165ed branch: main author: Victor Stinner <vstin...@python.org> committer: vstinner <vstin...@python.org> date: 2025-05-13T15:31:41+02:00 summary:
gh-133968: Add fast path to PyUnicodeWriter_WriteStr() (#133969) Don't call PyObject_Str() if the input type is str. files: M Objects/unicodeobject.c diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index cd26494ad8f1d6..aa94fb91e65fc3 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); } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com