From f48323e3b3336eeb787d94718464e527612ed0fb Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 5 Oct 2011 23:27:08 +0200 Subject: [PATCH] replace() uses unicode_fromascii() if the input and replace string is ASCII --- Objects/unicodeobject.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index bf2b32a9363..a0d3056b7f7 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)