Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion numcodecs/vlen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ class VLenBytes(Codec):
l = lengths[i]
store_le32(<uint8_t*>data, l)
data += 4
encv = PyBytes_AS_STRING(values[i])
b = values[i]
if b is None or b == 0: # treat these as missing value, normalize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like on line 231? It seems like l = 0 in this case, there is nothing to copy, and these operations are wasted. I might be wrong...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't pass a bytes object, you will hit this assert when calling PyBytes_AS_STRING: https://github.com/python/cpython/blob/40fff90ae3d46843bb9d27c6a53ef61c861a3bb4/Include/cpython/bytesobject.h#L21

it would be equivalent to skip the PyBytes_AS_STRING and memcpy entirely if l = 0. Shall I update the PR to do that instead?

b = b''
encv = PyBytes_AS_STRING(b)
memcpy(data, encv, l)
data += l

Expand Down