From: Victor Stinner Date: Fri, 30 Sep 2011 23:16:59 +0000 (+0200) Subject: PyUnicode_FromObject() reuses PyUnicode_Copy() X-Git-Tag: v3.3.0a1~1421 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2219e0a37e8dc7d4518b7e3958e918fdac217e07;p=thirdparty%2FPython%2Fcpython.git PyUnicode_FromObject() reuses PyUnicode_Copy() * PyUnicode_Copy() is faster than substring() * Fix also a compiler warning --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4b6f651673ee..810ac1e9e0fa 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2052,9 +2052,7 @@ PyUnicode_FromObject(register PyObject *obj) if (PyUnicode_Check(obj)) { /* For a Unicode subtype that's not a Unicode object, return a true Unicode object with the same data. */ - if (PyUnicode_READY(obj) == -1) - return NULL; - return substring((PyUnicodeObject *)obj, 0, PyUnicode_GET_LENGTH(obj)); + return PyUnicode_Copy(obj); } PyErr_Format(PyExc_TypeError, "Can't convert '%.100s' object to str implicitly", @@ -11465,7 +11463,7 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args) return (PyObject*) self; } else - return PyUnicode_Copy(self); + return PyUnicode_Copy((PyObject*)self); } fill = width - _PyUnicode_LENGTH(self);