Skip to content

Commit

Permalink
gh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr() (#125214)
Browse files Browse the repository at this point in the history
PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call
directly _PyLong_FormatWriter() if the argument is an int.
  • Loading branch information
vstinner authored Oct 9, 2024
1 parent 0c5a48c commit ee3167b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13632,6 +13632,10 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
int
PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
{
if (Py_TYPE(obj) == &PyLong_Type) {
return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0);
}

PyObject *str = PyObject_Str(obj);
if (str == NULL) {
return -1;
Expand All @@ -13646,6 +13650,10 @@ PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
int
PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
{
if (Py_TYPE(obj) == &PyLong_Type) {
return _PyLong_FormatWriter((_PyUnicodeWriter*)writer, obj, 10, 0);
}

PyObject *repr = PyObject_Repr(obj);
if (repr == NULL) {
return -1;
Expand Down

0 comments on commit ee3167b

Please sign in to comment.