-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[move][stdlib] Add vector::split_off and vector::replace library methods #14752
Conversation
⏱️ 1h 11m total CI duration on this PR
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## igor/move_mem_swap #14752 +/- ##
=====================================================
Coverage ? 59.8%
=====================================================
Files ? 854
Lines ? 208239
Branches ? 0
=====================================================
Hits ? 124599
Misses ? 83640
Partials ? 0 ☔ View full report in Codecov by Sentry. |
in the summary: "remove - which replaces value at particular index." : "remove" should be "replace" 😂 |
6e1add6
to
9e1d6af
Compare
9e1d6af
to
0d2ea8f
Compare
06d6cb3
to
55169e7
Compare
0d2ea8f
to
2253183
Compare
55169e7
to
4ba492b
Compare
4ba492b
to
6db4bf8
Compare
2253183
to
0f08236
Compare
/// Returns a newly allocated vector containing the elements in the range [at, len). | ||
/// After the call, the original vector will be left containing the elements [0, at) | ||
/// with its previous capacity unchanged. | ||
public fun split_off<Element>(self: &mut vector<Element>, at: u64): vector<Element> { |
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.
what's the diff with trim
?
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.
I believe it's better to make trim native tho
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.
ah, didn't realize, it is the same.
I think trim is a poor name for that - trim for a vector generally means make the capacity be equal to it's size.
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.
the move vector seems not to have the concept of capacity
...
idk who added this... but push_back
one by one is not that efficient? :)
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.
I did that in #14862, let me just merge this into that PR.
6db4bf8
to
bd33c50
Compare
merged into #14862 |
Description
When we store un-drop-able objects in a vector, handling changes to vector needs to be done without dropping any elements in the process (or creating temporary ones).
Adding two missing utilities to help with that:
Both could have more efficient implementations, if implemented in rust. But seems like that is the case for many functions in vector.move, so starting with straightforward implementation.
How Has This Been Tested?
provided unit tests
Type of Change
Which Components or Systems Does This Change Impact?
Checklist