mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
0c5a48c1c9
commit
ee3167b978
|
@ -13632,6 +13632,10 @@ _PyUnicodeWriter_WriteStr(_PyUnicodeWriter *writer, PyObject *str)
|
||||||
int
|
int
|
||||||
PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
|
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);
|
PyObject *str = PyObject_Str(obj);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -13646,6 +13650,10 @@ PyUnicodeWriter_WriteStr(PyUnicodeWriter *writer, PyObject *obj)
|
||||||
int
|
int
|
||||||
PyUnicodeWriter_WriteRepr(PyUnicodeWriter *writer, PyObject *obj)
|
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);
|
PyObject *repr = PyObject_Repr(obj);
|
||||||
if (repr == NULL) {
|
if (repr == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue