From: Victor Stinner Date: Wed, 5 Oct 2011 21:27:08 +0000 (+0200) Subject: replace() uses unicode_fromascii() if the input and replace string is ASCII X-Git-Tag: v3.3.0a1~1300 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f48323e3b3336eeb787d94718464e527612ed0fb;p=thirdparty%2FPython%2Fcpython.git replace() uses unicode_fromascii() if the input and replace string is ASCII --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index bf2b32a93634..a0d3056b7f7a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9708,7 +9708,10 @@ replace(PyObject *self, PyObject *str1, sbuf + PyUnicode_KIND_SIZE(rkind, i), PyUnicode_KIND_SIZE(rkind, slen-i)); } - u = PyUnicode_FromKindAndData(rkind, res, new_size); + 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); PyMem_Free(res); } if (srelease)