summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-02 20:22:42 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-02 20:22:42 (GMT)
commit2bc4d95bb67a0bcddec5b76e7f7b5d10b098aa49 (patch)
tree22819b8136a525a7c919d6d7a91c4de94fc10016 /Objects/bytearrayobject.c
parentd8f0d922d53a8f7bb64c1fda26be386bd2e3d958 (diff)
downloadcpython-2bc4d95bb67a0bcddec5b76e7f7b5d10b098aa49.zip
cpython-2bc4d95bb67a0bcddec5b76e7f7b5d10b098aa49.tar.gz
cpython-2bc4d95bb67a0bcddec5b76e7f7b5d10b098aa49.tar.bz2
Issue #21233: Revert bytearray(int) optimization using calloc()
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 68b9c4a..5b75705 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -813,21 +813,9 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
}
else {
if (count > 0) {
- void *sval;
- Py_ssize_t alloc;
-
- assert (Py_SIZE(self) == 0);
-
- alloc = count + 1;
- sval = PyObject_Calloc(1, alloc);
- if (sval == NULL)
+ if (PyByteArray_Resize((PyObject *)self, count))
return -1;
-
- PyObject_Free(self->ob_bytes);
-
- self->ob_bytes = self->ob_start = sval;
- Py_SIZE(self) = count;
- self->ob_alloc = alloc;
+ memset(PyByteArray_AS_STRING(self), 0, count);
}
return 0;
}