]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
replace() uses unicode_fromascii() if the input and replace string is ASCII
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Oct 2011 21:27:08 +0000 (23:27 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Oct 2011 21:27:08 +0000 (23:27 +0200)
Objects/unicodeobject.c

index bf2b32a936346d60a27ae8ccc9996b6c372e9c3f..a0d3056b7f7a9e04ac7311a1388b88ad6d5a2dc8 100644 (file)
@@ -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)