tl;dr Given a Sequence of memoryview, how can I create a single bytes instance without creating intermediate bytes instances?
The naive approach creates many intermediary instances of bytes
def create_bytes(seq_mv: Sequence[memoryview]) -> bytes:
data = bytes()
for mv in seq_mv:
data = data + bytes(mv)
return data
The function create_bytes creates len(seq_mv) + 1 instances of bytes during execution. That is inefficient.
I want create_bytes to create one new bytes instance during execution.
bytes().join(seq_mv)?joinis here in the docs, too. Thanks!