Skip to content

Commit 5632e93

Browse files
[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 fe9f6e8) Co-authored-by: Victor Stinner <[email protected]>
1 parent 69b4387 commit 5632e93

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Objects/unicodeobject.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -13954,7 +13954,12 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
1395413954
int
1395513955
PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
1395613956
{
13957-
if (Py_TYPE(obj) == &PyLong_Type) {
13957+
PyTypeObject *type = Py_TYPE(obj);
13958+
if (type == &PyUnicode_Type) {
13959+
return _PyUnicodeWriter_WriteStr((_PyUnicodeWriter*)writer, obj);
13960+
}
13961+
13962+
if (type == &PyLong_Type) {
1395813963
return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0);
1395913964
}
1396013965

0 commit comments

Comments
 (0)