Skip to content

Commit ee3167b

Browse files
authored
gh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr() (#125214)
PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call directly _PyLong_FormatWriter() if the argument is an int.
1 parent 0c5a48c commit ee3167b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Objects/unicodeobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13632,6 +13632,10 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
1363213632
int
1363313633
PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
1363413634
{
13635+
if (Py_TYPE(obj) == &PyLong_Type) {
13636+
return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0);
13637+
}
13638+
1363513639
PyObject *str = PyObject_Str(obj);
1363613640
if (str == NULL) {
1363713641
return -1;
@@ -13646,6 +13650,10 @@ PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
1364613650
int
1364713651
PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
1364813652
{
13653+
if (Py_TYPE(obj) == &PyLong_Type) {
13654+
return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0);
13655+
}
13656+
1364913657
PyObject *repr = PyObject_Repr(obj);
1365013658
if (repr == NULL) {
1365113659
return -1;

0 commit comments

Comments
 (0)