diff options
author | Victor Stinner <vstinner@python.org> | 2024-10-09 22:01:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 22:01:02 (GMT) |
commit | ee3167b9787bf9424d5637a224233de775450231 (patch) | |
tree | 90ceea3abc20b75d8ab6f3811864acbb65eb2672 | |
parent | 0c5a48c1c9039eb1ce25a96c43505c4de0a0b9d7 (diff) | |
download | cpython-ee3167b9787bf9424d5637a224233de775450231.zip cpython-ee3167b9787bf9424d5637a224233de775450231.tar.gz cpython-ee3167b9787bf9424d5637a224233de775450231.tar.bz2 |
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.
-rw-r--r-- | Objects/unicodeobject.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4ea7d5f..a9b3324 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; |