Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core/types): avoid a copy in Buffer::to_bytes() by cloning contiguous bytes #4858

Merged
merged 2 commits into from
Jul 6, 2024
Merged

feat(core/types): avoid a copy in Buffer::to_bytes() by cloning contiguous bytes #4858

merged 2 commits into from
Jul 6, 2024

Conversation

LDeakin
Copy link
Contributor

@LDeakin LDeakin commented Jul 6, 2024

Buffer::into_bytes is zero copy if the underlying bytes are contiguous. Also implements From<Buffer> for Bytes.

Fixes #4857.

`Buffer::into_bytes` is zero copy if the underlying bytes are contiguous.
Also implements `From<Buffer>` for `Bytes`.
@LDeakin LDeakin requested a review from Xuanwo as a code owner July 6, 2024 01:29
@github-actions github-actions bot requested a review from G-XD July 6, 2024 01:29
@LDeakin LDeakin changed the title feat(core): Add Buffer::into_bytes() feat(core/types): Add Buffer::into_bytes() Jul 6, 2024
LDeakin added a commit to LDeakin/zarrs that referenced this pull request Jul 6, 2024
@Xuanwo
Copy link
Member

Xuanwo commented Jul 6, 2024

Hi, it's by design that we didn't implement into_bytes and From<Bytes> for Buffer. I believe we can use Bytes::clone in to_bytes to save the cost instead of adding into_bytes.

@LDeakin LDeakin changed the title feat(core/types): Add Buffer::into_bytes() feat(core/types): avoid a copy in Buffer::to_bytes() by cloning contiguous bytes Jul 6, 2024
Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@LDeakin
Copy link
Contributor Author

LDeakin commented Jul 6, 2024

Great! That is much cleaner.

@Xuanwo Xuanwo merged commit 6de4459 into apache:main Jul 6, 2024
219 checks passed
LDeakin added a commit to LDeakin/zarrs that referenced this pull request Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting a Buffer to Bytes always requires a copy
2 participants