From 2219e0a37e8dc7d4518b7e3958e918fdac217e07 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 1 Oct 2011 01:16:59 +0200 Subject: [PATCH] PyUnicode_FromObject() reuses PyUnicode_Copy() * PyUnicode_Copy() is faster than substring() * Fix also a compiler warning --- Objects/unicodeobject.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4b6f651673e..810ac1e9e0f 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);