Commit cba4212f authored by Stefan Behnel's avatar Stefan Behnel

save a malloc() call when instantiating cython.array()

--HG--
extra : amend_source : 8ea50b285fc8d55899450c179754d7c2aba94591
parent 91a19d19
...@@ -132,13 +132,12 @@ cdef class array: ...@@ -132,13 +132,12 @@ cdef class array:
self._format = format self._format = format
self.format = self._format self.format = self._format
self._shape = <Py_ssize_t *> malloc(sizeof(Py_ssize_t)*self.ndim) # use single malloc() for both shape and strides
self._strides = <Py_ssize_t *> malloc(sizeof(Py_ssize_t)*self.ndim) self._shape = <Py_ssize_t *> malloc(sizeof(Py_ssize_t)*self.ndim*2)
self._strides = self._shape + self.ndim
if not self._shape or not self._strides: if not self._shape:
free(self._shape) raise MemoryError("unable to allocate shape and strides.")
free(self._strides)
raise MemoryError("unable to allocate shape or strides.")
# cdef Py_ssize_t dim, stride # cdef Py_ssize_t dim, stride
idx = 0 idx = 0
...@@ -214,8 +213,6 @@ cdef class array: ...@@ -214,8 +213,6 @@ cdef class array:
refcount_objects_in_slice(self.data, self._shape, refcount_objects_in_slice(self.data, self._shape,
self._strides, self.ndim, False) self._strides, self.ndim, False)
free(self.data) free(self.data)
free(self._strides)
free(self._shape) free(self._shape)
property memview: property memview:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment