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

Make Slab::clone_from avoid reallocation #137

Merged
merged 1 commit into from
Aug 21, 2023

Conversation

vs-andresfranco
Copy link
Contributor

#[derive(Clone)] does not automatically implement clone_from, this is a known issue, it seems because of compile times.

However, clone_from has a real use when a data structure contains heap-allocated storage, such as Box, Vec, etc: it avoids making a new memory allocation if the "host" struct has enough space already.

This PR fixes that, removing the #derive and implementing Clone manually, avoiding a new allocation when using Slab::clone_from.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks. Looks good to me.

@Darksonn Darksonn merged commit 8718c40 into tokio-rs:master Aug 21, 2023
6 of 7 checks passed
@Darksonn Darksonn mentioned this pull request Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants