[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 fe9f6e829a)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2025-05-13 15:58:25 +02:00 committed by GitHub
parent 69b4387f78
commit 5632e93f46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}