Commit 036637f1 authored by Stefan Behnel's avatar Stefan Behnel

Remove a tiny bit of time overhead in mockbuffer test support.

parent ddc9a18c
......@@ -31,11 +31,12 @@ cdef class MockBuffer:
def __init__(self, label, data, shape=None, strides=None, format=None, writable=True, offset=0):
# It is important not to store references to data after the constructor
# as refcounting is checked on object buffers.
cdef Py_ssize_t x, s, cumprod, itemsize
self.label = label
self.release_ok = True
self.log = ""
self.offset = offset
self.itemsize = self.get_itemsize()
self.itemsize = itemsize = self.get_itemsize()
self.writable = writable
if format is None: format = self.get_default_format()
if shape is None: shape = (len(data),)
......@@ -48,7 +49,7 @@ cdef class MockBuffer:
strides.append(cumprod)
cumprod *= s
strides.reverse()
strides = [x * self.itemsize for x in strides]
strides = [x * itemsize for x in strides]
suboffsets = [-1] * len(shape)
datashape = [len(data)]
p = data
......@@ -61,8 +62,10 @@ cdef class MockBuffer:
self.ndim = <int>len(datashape)
shape = datashape
self.buffer = self.create_indirect_buffer(data, shape)
suboffsets = [0] * (self.ndim-1) + [-1]
strides = [sizeof(void*)] * (self.ndim-1) + [self.itemsize]
suboffsets = [0] * self.ndim
suboffsets[-1] = -1
strides = [sizeof(void*)] * self.ndim
strides[-1] = itemsize
self.suboffsets = self.list_to_sizebuf(suboffsets)
else:
# strided and/or simple access
......@@ -75,7 +78,7 @@ cdef class MockBuffer:
except AttributeError:
pass
self.format = format
self.len = len(data) * self.itemsize
self.len = len(data) * itemsize
self.strides = self.list_to_sizebuf(strides)
self.shape = self.list_to_sizebuf(shape)
......@@ -119,6 +122,7 @@ cdef class MockBuffer:
return buf
cdef Py_ssize_t* list_to_sizebuf(self, l):
cdef Py_ssize_t i, x
cdef size_t n = <size_t>len(l) * sizeof(Py_ssize_t)
cdef Py_ssize_t* buf = <Py_ssize_t*>stdlib.malloc(n)
for i, x in enumerate(l):
......
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