diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-11-19 21:49:09 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-11-19 21:49:09 (GMT) |
commit | 46cc6d11020d0bfa7b245b18679a613e9bc2b325 (patch) | |
tree | 28f96eb5e12156eb4039be6191e699759a5af720 /Objects/bytearrayobject.c | |
parent | 3b30e2c86d45f6718b0a79784cda36b2cf30a9db (diff) | |
download | cpython-46cc6d11020d0bfa7b245b18679a613e9bc2b325.zip cpython-46cc6d11020d0bfa7b245b18679a613e9bc2b325.tar.gz cpython-46cc6d11020d0bfa7b245b18679a613e9bc2b325.tar.bz2 |
make sure that bytearray methods return a new bytearray even if there is no change
Fixes #4348
Reviewed by Brett
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index c4fc37f..99bb0f2 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -1423,7 +1423,7 @@ bytes_translate(PyByteArrayObject *self, PyObject *args) { 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; @@ -1469,14 +1469,8 @@ bytes_translate(PyByteArrayObject *self, PyObject *args) /* 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; } @@ -1491,13 +1485,6 @@ bytes_translate(PyByteArrayObject *self, PyObject *args) 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) @@ -1526,15 +1513,10 @@ done: !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) { - if (PyByteArray_CheckExact(self)) { - Py_INCREF(self); - return (PyByteArrayObject *)self; - } return (PyByteArrayObject *)PyByteArray_FromStringAndSize( PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self)); |