Skip to content

Commit f91c283

Browse files
committed
Write directly to output array in VLen*
1 parent 1ab9983 commit f91c283

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

numcodecs/vlen.pyx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ class VLenArray(Codec):
428428
const Py_buffer* buf_pb
429429
const char* data
430430
const char* data_end
431+
object v
432+
memoryview v_mv
433+
Py_buffer* v_pb
431434
Py_ssize_t i, l, n_items, data_length
432435

433436
# obtain memoryview
@@ -465,7 +468,14 @@ class VLenArray(Codec):
465468
data += 4
466469
if data + l > data_end:
467470
raise ValueError('corrupt buffer, data seem truncated')
468-
out[i] = np.frombuffer(data[:l], dtype=self.dtype)
471+
472+
# Create & fill array value
473+
v = np.empty((l,), dtype="uint8").view(self.dtype)
474+
v_mv = memoryview(v)
475+
v_pb = PyMemoryView_GET_BUFFER(v_mv)
476+
memcpy(v_pb.buf, data, l)
477+
478+
out[i] = v
469479
data += l
470480

471481
return out

0 commit comments

Comments
 (0)