Skip to content

Commit

Permalink
pythongh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr()
Browse files Browse the repository at this point in the history
PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call
directly _PyLong_FormatWriter() if the object is an int.
  • Loading branch information
vstinner committed Oct 9, 2024
1 parent 9bda775 commit 3400d0a
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 @@ -13605,6 +13605,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 @@ -13619,6 +13623,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 3400d0a

Please sign in to comment.