Merged revisions 67291 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67291 | benjamin.peterson | 2008-11-19 15:49:09 -0600 (Wed, 19 Nov 2008) | 5 lines

  make sure that bytearray methods return a new bytearray even if there is no change

  Fixes #4348
  Reviewed by Brett
........
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 997a835..707c844 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1351,7 +1351,7 @@
 {
     register char *input, *output;
     register const char *table;
-    register Py_ssize_t i, c, changed = 0;
+    register Py_ssize_t i, c;
     PyObject *input_obj = (PyObject*)self;
     const char *output_start;
     Py_ssize_t inlen;
@@ -1397,14 +1397,8 @@
         /* If no deletions are required, use faster code */
         for (i = inlen; --i >= 0; ) {
             c = Py_CHARMASK(*input++);
-            if (Py_CHARMASK((*output++ = table[c])) != c)
-                changed = 1;
+            *output++ = table[c];
         }
-        if (changed || !PyByteArray_CheckExact(input_obj))
-            goto done;
-        Py_DECREF(result);
-        Py_INCREF(input_obj);
-        result = input_obj;
         goto done;
     }
 
@@ -1419,13 +1413,6 @@
         if (trans_table[c] != -1)
             if (Py_CHARMASK(*output++ = (char)trans_table[c]) == c)
                     continue;
-        changed = 1;
-    }
-    if (!changed && PyByteArray_CheckExact(input_obj)) {
-        Py_DECREF(result);
-        Py_INCREF(input_obj);
-        result = input_obj;
-        goto done;
     }
     /* Fix the size of the resulting string */
     if (inlen > 0)
@@ -1454,8 +1441,7 @@
    !memcmp(target+offset+1, pattern+1, length-2) )
 
 
-/* Bytes ops must return a string.  */
-/* If the object is subclass of bytes, create a copy */
+/* Bytes ops must return a string, create a copy */
 Py_LOCAL(PyByteArrayObject *)
 return_self(PyByteArrayObject *self)
 {