PyUnicode_FromObject() reuses PyUnicode_Copy()

* PyUnicode_Copy() is faster than substring()
 * Fix also a compiler warning
This commit is contained in:
Victor Stinner 2011-10-01 01:16:59 +02:00
parent 9e5bd6c544
commit 2219e0a37e

View file

@ -2052,9 +2052,7 @@ PyUnicode_FromObject(register PyObject *obj)
if (PyUnicode_Check(obj)) { if (PyUnicode_Check(obj)) {
/* For a Unicode subtype that's not a Unicode object, /* For a Unicode subtype that's not a Unicode object,
return a true Unicode object with the same data. */ return a true Unicode object with the same data. */
if (PyUnicode_READY(obj) == -1) return PyUnicode_Copy(obj);
return NULL;
return substring((PyUnicodeObject *)obj, 0, PyUnicode_GET_LENGTH(obj));
} }
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"Can't convert '%.100s' object to str implicitly", "Can't convert '%.100s' object to str implicitly",
@ -11465,7 +11463,7 @@ unicode_zfill(PyUnicodeObject *self, PyObject *args)
return (PyObject*) self; return (PyObject*) self;
} }
else else
return PyUnicode_Copy(self); return PyUnicode_Copy((PyObject*)self);
} }
fill = width - _PyUnicode_LENGTH(self); fill = width - _PyUnicode_LENGTH(self);