From: Victor Stinner Date: Wed, 9 Oct 2024 22:01:02 +0000 (+0200) Subject: gh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr() (#125214) X-Git-Tag: v3.14.0a1~105 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee3167b9787bf9424d5637a224233de775450231;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4ea7d5f380e9..a9b332481638 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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; @@ -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;