Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39aba4f

Browse files
committed
Use the small object allocator for small bytearrays
1 parent c3dfc98 commit 39aba4f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Objects/bytearrayobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ PyByteArray_FromStringAndSize(const char *bytes, Py_ssize_t size)
139139
}
140140
else {
141141
alloc = size + 1;
142-
new->ob_bytes = PyMem_Malloc(alloc);
142+
new->ob_bytes = PyObject_Malloc(alloc);
143143
if (new->ob_bytes == NULL) {
144144
Py_DECREF(new);
145145
return PyErr_NoMemory();
@@ -209,7 +209,7 @@ PyByteArray_Resize(PyObject *self, Py_ssize_t size)
209209
alloc = size + 1;
210210
}
211211

212-
sval = PyMem_Realloc(((PyByteArrayObject *)self)->ob_bytes, alloc);
212+
sval = PyObject_Realloc(((PyByteArrayObject *)self)->ob_bytes, alloc);
213213
if (sval == NULL) {
214214
PyErr_NoMemory();
215215
return -1;
@@ -870,7 +870,7 @@ bytearray_repr(PyByteArrayObject *self)
870870
}
871871

872872
newsize = 15 + length * 4;
873-
buffer = PyMem_Malloc(newsize);
873+
buffer = PyObject_Malloc(newsize);
874874
if (buffer == NULL) {
875875
PyErr_NoMemory();
876876
return NULL;
@@ -924,7 +924,7 @@ bytearray_repr(PyByteArrayObject *self)
924924
}
925925

926926
v = PyUnicode_DecodeASCII(buffer, p - buffer, NULL);
927-
PyMem_Free(buffer);
927+
PyObject_Free(buffer);
928928
return v;
929929
}
930930

@@ -1020,7 +1020,7 @@ bytearray_dealloc(PyByteArrayObject *self)
10201020
PyErr_Print();
10211021
}
10221022
if (self->ob_bytes != 0) {
1023-
PyMem_Free(self->ob_bytes);
1023+
PyObject_Free(self->ob_bytes);
10241024
}
10251025
Py_TYPE(self)->tp_free((PyObject *)self);
10261026
}

0 commit comments

Comments
 (0)