]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyUnicode_FromObject() reuses PyUnicode_Copy()
authorVictor Stinner <victor.stinner@haypocalc.com>
Fri, 30 Sep 2011 23:16:59 +0000 (01:16 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Fri, 30 Sep 2011 23:16:59 +0000 (01:16 +0200)
 * PyUnicode_Copy() is faster than substring()
 * Fix also a compiler warning

Objects/unicodeobject.c

index 4b6f651673ee08c4ecc7c970d19bb582aa401914..810ac1e9e0fa0feca6e7b444f2c47cf0fed27e9d 100644 (file)
@@ -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);