Commit f48323e3 authored by Victor Stinner's avatar Victor Stinner

replace() uses unicode_fromascii() if the input and replace string is ASCII

parent 0617b6e1
...@@ -9708,6 +9708,9 @@ replace(PyObject *self, PyObject *str1, ...@@ -9708,6 +9708,9 @@ replace(PyObject *self, PyObject *str1,
sbuf + PyUnicode_KIND_SIZE(rkind, i), sbuf + PyUnicode_KIND_SIZE(rkind, i),
PyUnicode_KIND_SIZE(rkind, slen-i)); PyUnicode_KIND_SIZE(rkind, slen-i));
} }
if (PyUnicode_IS_ASCII(self) && PyUnicode_IS_ASCII(str2))
u = unicode_fromascii((unsigned char*)res, new_size);
else
u = PyUnicode_FromKindAndData(rkind, res, new_size); u = PyUnicode_FromKindAndData(rkind, res, new_size);
PyMem_Free(res); PyMem_Free(res);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment