]> granicus.if.org Git - python/commitdiff
More on bug 460020: disable many optimizations of unicode subclasses.
authorTim Peters <tim.peters@gmail.com>
Wed, 12 Sep 2001 03:03:31 +0000 (03:03 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 12 Sep 2001 03:03:31 +0000 (03:03 +0000)
Lib/test/test_descr.py
Objects/unicodeobject.c

index a29eb2312c5d625657c8d2586a05d324cdabaeb7..b791037aa580087f4e9354eff230ee7a6b345b4f 100644 (file)
@@ -1486,13 +1486,25 @@ def inherits():
     verify(str(s) == base)
     verify(str(s).__class__ is str)
     verify((s + "").__class__ is str)
+    verify(s + "" == base)
     verify(("" + s).__class__ is str)
+    verify("" + s == base)
     verify((s * 0).__class__ is str)
+    verify(s * 0 == "")
     verify((s * 1).__class__ is str)
+    verify(s * 1 == base)
     verify((s * 2).__class__ is str)
+    verify(s * 2 == base + base)
     verify(s[:].__class__ is str)
+    verify(s[:] == base)
     verify(s[0:0].__class__ is str)
+    verify(s[0:0] == "")
     verify(s.strip().__class__ is str)
+    verify(s.strip() == base)
+    verify(s.lstrip().__class__ is str)
+    verify(s.lstrip() == base)
+    verify(s.rstrip().__class__ is str)
+    verify(s.rstrip() == base)
     identitytab = ''.join([chr(i) for i in range(256)])
     verify(s.translate(identitytab).__class__ is str)
     verify(s.translate(identitytab) == base)
@@ -1507,6 +1519,8 @@ def inherits():
     verify(s.rjust(len(s)) == base)
     verify(s.center(len(s)).__class__ is str)
     verify(s.center(len(s)) == base)
+    verify(s.lower().__class__ is str)
+    verify(s.lower() == base)
 
     class madunicode(unicode):
         _rev = None
@@ -1520,9 +1534,48 @@ def inherits():
     u = madunicode("ABCDEF")
     verify(u.rev() == madunicode(u"FEDCBA"))
     verify(u.rev().rev() == madunicode(u"ABCDEF"))
-    u = madunicode(u"12345")
-    verify(unicode(u) == u"12345")
+    base = u"12345"
+    u = madunicode(base)
+    verify(unicode(u) == base)
     verify(unicode(u).__class__ is unicode)
+    verify(u.strip().__class__ is unicode)
+    verify(u.strip() == base)
+    verify(u.lstrip().__class__ is unicode)
+    verify(u.lstrip() == base)
+    verify(u.rstrip().__class__ is unicode)
+    verify(u.rstrip() == base)
+    verify(u.replace(u"x", u"x").__class__ is unicode)
+    verify(u.replace(u"x", u"x") == base)
+    verify(u.replace(u"xy", u"xy").__class__ is unicode)
+    verify(u.replace(u"xy", u"xy") == base)
+    verify(u.center(len(u)).__class__ is unicode)
+    verify(u.center(len(u)) == base)
+    verify(u.ljust(len(u)).__class__ is unicode)
+    verify(u.ljust(len(u)) == base)
+    verify(u.rjust(len(u)).__class__ is unicode)
+    verify(u.rjust(len(u)) == base)
+    verify(u.lower().__class__ is unicode)
+    verify(u.lower() == base)
+    verify(u.upper().__class__ is unicode)
+    verify(u.upper() == base)
+    verify(u.capitalize().__class__ is unicode)
+    verify(u.capitalize() == base)
+    verify(u.title().__class__ is unicode)
+    verify(u.title() == base)
+    verify((u + u"").__class__ is unicode)
+    verify(u + u"" == base)
+    verify((u"" + u).__class__ is unicode)
+    verify(u"" + u == base)
+    verify((u * 0).__class__ is unicode)
+    verify(u * 0 == u"")
+    verify((u * 1).__class__ is unicode)
+    verify(u * 1 == base)
+    verify((u * 2).__class__ is unicode)
+    verify(u * 2 == base + base)
+    verify(u[:].__class__ is unicode)
+    verify(u[:] == base)
+    verify(u[0:0].__class__ is unicode)
+    verify(u[0:0] == u"")
 
 def all():
     lists()
index a50b9256c91b411eac12b5f88f44420d89a697b3..c5912b516763c349f25b5a648000a77f8be3ad92 100644 (file)
@@ -2703,7 +2703,7 @@ PyObject *fixup(PyUnicodeObject *self,
 
     Py_UNICODE_COPY(u->str, self->str, self->length);
 
-    if (!fixfct(u)) {
+    if (!fixfct(u) && PyUnicode_CheckExact(self)) {
        /* fixfct should return TRUE if it modified the buffer. If
           FALSE, return a reference to the original buffer instead
           (to save space, not time) */
@@ -2934,7 +2934,7 @@ PyUnicodeObject *pad(PyUnicodeObject *self,
     if (right < 0)
         right = 0;
 
-    if (left == 0 && right == 0) {
+    if (left == 0 && right == 0 && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return self;
     }
@@ -3161,7 +3161,7 @@ PyObject *strip(PyUnicodeObject *self,
         while (end > start && Py_UNICODE_ISSPACE(p[end-1]))
             end--;
 
-    if (start == 0 && end == self->length) {
+    if (start == 0 && end == self->length && PyUnicode_CheckExact(self)) {
         /* couldn't strip anything off, return original string */
         Py_INCREF(self);
         return (PyObject*) self;
@@ -3188,7 +3188,8 @@ PyObject *replace(PyUnicodeObject *self,
         int i;
 
         /* replace characters */
-        if (!findchar(self->str, self->length, str1->str[0])) {
+        if (!findchar(self->str, self->length, str1->str[0]) &&
+            PyUnicode_CheckExact(self)) {
             /* nothing to replace, return original string */
             Py_INCREF(self);
             u = self;
@@ -3220,7 +3221,7 @@ PyObject *replace(PyUnicodeObject *self,
         n = count(self, 0, self->length, str1);
         if (n > maxcount)
             n = maxcount;
-        if (n == 0) {
+        if (n == 0 && PyUnicode_CheckExact(self)) {
             /* nothing to replace, return original string */
             Py_INCREF(self);
             u = self;
@@ -3329,7 +3330,7 @@ unicode_center(PyUnicodeObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args, "i:center", &width))
         return NULL;
 
-    if (self->length >= width) {
+    if (self->length >= width && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return (PyObject*) self;
     }
@@ -4085,7 +4086,7 @@ unicode_ljust(PyUnicodeObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args, "i:ljust", &width))
         return NULL;
 
-    if (self->length >= width) {
+    if (self->length >= width && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return (PyObject*) self;
     }
@@ -4126,7 +4127,7 @@ unicode_repeat(PyUnicodeObject *str, int len)
     if (len < 0)
         len = 0;
 
-    if (len == 1) {
+    if (len == 1 && PyUnicode_CheckExact(str)) {
         /* no repeat, return original string */
         Py_INCREF(str);
         return (PyObject*) str;
@@ -4309,7 +4310,7 @@ unicode_rjust(PyUnicodeObject *self, PyObject *args)
     if (!PyArg_ParseTuple(args, "i:rjust", &width))
         return NULL;
 
-    if (self->length >= width) {
+    if (self->length >= width && PyUnicode_CheckExact(self)) {
         Py_INCREF(self);
         return (PyObject*) self;
     }
@@ -4338,7 +4339,7 @@ unicode_slice(PyUnicodeObject *self, int start, int end)
         end = 0;
     if (end > self->length)
         end = self->length;
-    if (start == 0 && end == self->length) {
+    if (start == 0 && end == self->length && PyUnicode_CheckExact(self)) {
         /* full slice, return original string */
         Py_INCREF(self);
         return (PyObject*) self;