-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Improve clone_from
impls for collections
#28602
Conversation
@bors r+ Nice! |
📌 Commit 85be55b has been approved by |
⌛ Testing commit 85be55b with merge 8de4886... |
Did you push a new commit after bors tested the old one. What was the change? |
for (place, thing) in self.iter_mut().zip(other) { | ||
place.clone_from(thing) | ||
{ | ||
let src = &other[..len]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trick might warrant a comment.
@bluss Yeah, I pushed a new commit, so bors hasn't tested the new one yet. I removed an unnecessary call to I'll add a comment that explains the trick and re-push. |
Great |
Hmm, instead of using the trick, should I just use a more explicit (and less finicky) |
It's almost about time we package up this "zip slices" pattern now in a function or iterator actually, since we have to use it in a lot of places. I think your question is interesting:
(2) can absolutely be called fragile. I still like (2) better since it's safe, it degrades well (still correct even if the optimizer's behavior changes). |
It's actually already present in |
yes, for clone in particular it seems it is. We can reuse that here, then. |
Updated. |
Now it's beautiful @bors r+ |
📌 Commit 2f1084a has been approved by |
⌛ Testing commit 2f1084a with merge 450f87f... |
💔 Test failed - auto-mac-64-opt |
Before: test dst_bigger::src_100_dst_1000::clone ... bench: 34 ns/iter (+/- 1) test dst_bigger::src_100_dst_1000::clone_from ... bench: 75 ns/iter (+/- 3) test dst_bigger::src_10_dst_100::clone ... bench: 25 ns/iter (+/- 0) test dst_bigger::src_10_dst_100::clone_from ... bench: 9 ns/iter (+/- 1) test eq::src_1000_dst_1000::clone ... bench: 105 ns/iter (+/- 2) test eq::src_1000_dst_1000::clone_from ... bench: 593 ns/iter (+/- 21) test eq::src_100_dst_100::clone ... bench: 34 ns/iter (+/- 1) test eq::src_100_dst_100::clone_from ... bench: 75 ns/iter (+/- 1) test src_bigger::src_1000_dst_100::clone ... bench: 103 ns/iter (+/- 5) test src_bigger::src_1000_dst_100::clone_from ... bench: 148 ns/iter (+/- 5) test src_bigger::src_100_dst_10::clone ... bench: 34 ns/iter (+/- 1) test src_bigger::src_100_dst_10::clone_from ... bench: 20 ns/iter (+/- 0) After: test dst_bigger::src_100_dst_1000::clone ... bench: 34 ns/iter (+/- 2) test dst_bigger::src_100_dst_1000::clone_from ... bench: 15 ns/iter (+/- 1) test dst_bigger::src_10_dst_100::clone ... bench: 26 ns/iter (+/- 1) test dst_bigger::src_10_dst_100::clone_from ... bench: 7 ns/iter (+/- 0) test eq::src_1000_dst_1000::clone ... bench: 103 ns/iter (+/- 1) test eq::src_1000_dst_1000::clone_from ... bench: 85 ns/iter (+/- 4) test eq::src_100_dst_100::clone ... bench: 34 ns/iter (+/- 2) test eq::src_100_dst_100::clone_from ... bench: 15 ns/iter (+/- 1) test src_bigger::src_1000_dst_100::clone ... bench: 103 ns/iter (+/- 4) test src_bigger::src_1000_dst_100::clone_from ... bench: 90 ns/iter (+/- 2) test src_bigger::src_100_dst_10::clone ... bench: 34 ns/iter (+/- 2) test src_bigger::src_100_dst_10::clone_from ... bench: 20 ns/iter (+/- 0) Closes #28601.
Fixed the test failure. |
@bors r+ thanks! |
📌 Commit 97f2a32 has been approved by |
r? @bluss