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

Do not iterate elements in bounded queue/channel's destructor when needs_drop returns false #1057

Merged
merged 1 commit into from
Dec 23, 2023

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Dec 23, 2023

https://doc.rust-lang.org/std/mem/fn.needs_drop.html

Note that drop_in_place already performs this check, so if your workload can be reduced to some small number of drop_in_place calls, using this is unnecessary. In particular note that you can drop_in_place a slice, and that will do a single needs_drop check for all the values.

Types like Vec therefore just drop_in_place(&mut self[..]) without using needs_drop explicitly. Types like HashMap, on the other hand, have to drop values one at a time and should use this API.

@taiki-e taiki-e changed the title Do not iterate elements in bounded queue's destructor when needs_drop returns false Do not iterate elements in bounded queue/channel's destructor when needs_drop returns false Dec 23, 2023
@taiki-e taiki-e merged commit 1827fc4 into master Dec 23, 2023
24 checks passed
@taiki-e taiki-e deleted the taiki-e/needs_drop branch December 23, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant