-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Slice retain #71832
Slice retain #71832
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @shepmaster (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The slice retain method not dropping the values removed seems like an odd choice -- I would then guess that the user wanted to use Iterator::partition_in_place? Maybe we can update the Vec::retain method to use that iterator method? We should benchmark that. I would not be opposed to adding a |
@Mark-Simulacrum I share your concern, although, the pointer to the original slice remains valid, what would that mean if someone tried to access those dropped elements? We don't have that issue with Also the doc for |
What I took away from that comment is that this function should not be called |
Yes, that's what I meant, sorry, I should have been more clear. Because of that I don't think retain is viable on slices (since you can't really "shrink" them, just move things around in them). |
Perhaps that means that the order should be fixed. See also |
yes this makes sense. Whatever we decide to call it, we should link it to Vec::retain, so people looking for the slice counterpart can find it easily.
Yes, I saw that, but it's referring to the duplicates order, the retain method does not provide any guarantees on the discarded elements order either. Do you think that we should pick another algorithm that guaranties that both part's relative order is preserved? If it occurs that people have need for both parts, we could also return both, as was originally proposed for |
Interestingly, Iterator::partition_in_place is about twice faster than retain in small benchmarks I made |
Possibly. There's multiple things I can see:
I'd say that 4 is not useful (and could probably be done by inverting the condition on 1). The "second partition stays ordered" versions are only useful for the forms that make use of the second partition (e.g. not |
This seems to be another issue though. The goal of this PR is to add a
It seems that |
☔ The latest upstream changes (presumably #72747) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage: |
Yes sure |
Ping from triage: |
Closing due to inactivity. Feel free to reopen or create a new PR when you have time. (Actually i suggest creating a zulip topic to finish up the API design first in this case.) Thanks! |
adds
retain
method on slice. This meant moving theretain
implementation fromVec
toslice
and havingVec
'sretain
method rely onslice
's.tracking issue: #71831