summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-10-09 22:01:02 (GMT)
committerGitHub <noreply@github.com>2024-10-09 22:01:02 (GMT)
commitee3167b9787bf9424d5637a224233de775450231 (patch)
tree90ceea3abc20b75d8ab6f3811864acbb65eb2672
parent0c5a48c1c9039eb1ce25a96c43505c4de0a0b9d7 (diff)
downloadcpython-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.c8
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;