Skip to content

Optimize Clone implementation #146

New issue

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

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

Already on GitHub? # to your account

Merged
merged 3 commits into from
Mar 16, 2020
Merged

Optimize Clone implementation #146

merged 3 commits into from
Mar 16, 2020

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Mar 16, 2020

Two major changes:

  • clone_from is now implemented which can be used to skip memory allocation if the existing HashMap already has enough capacity.
  • [nightly] Specialization is used to optimize cloning when T: Copy into a simple memory copy.
  • [nightly] Specialization is used to reuse the existing capacity of a HashMap when clone_from is used. Specialization is needed because the Clone impl on HashMap is missing K: Hash + Eq, S: BuildHasher.

Fixes #112

@Amanieu Amanieu force-pushed the clone_from branch 3 times, most recently from 83de957 to c3396c0 Compare March 16, 2020 12:05
@Amanieu Amanieu force-pushed the clone_from branch 2 times, most recently from cb23a71 to 81b5f6e Compare March 16, 2020 14:50
@Amanieu Amanieu changed the title Implement clone_from for HashMap Optimize Clone implementation Mar 16, 2020
@Amanieu
Copy link
Member Author

Amanieu commented Mar 16, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 16, 2020

📌 Commit c9b320e has been approved by Amanieu

@bors
Copy link
Contributor

bors commented Mar 16, 2020

⌛ Testing commit c9b320e with merge 108822c...

@bors
Copy link
Contributor

bors commented Mar 16, 2020

☀️ Test successful - checks-travis
Approved by: Amanieu
Pushing 108822c to master...

@bors bors merged commit 108822c into rust-lang:master Mar 16, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 7, 2020
Update hashbrown to 0.8.1

This update includes:
- rust-lang/hashbrown#146, which improves the performance of `Clone` and implements `clone_from`.
- rust-lang/hashbrown#159, which reduces the size of `HashMap` by 8 bytes.
- rust-lang/hashbrown#162, which avoids creating small 1-element tables.

Fixes rust-lang#28481
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clone without unnecessary allocations
2 participants