-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Vec could use insert_all
and insert_all_move
methods
#15435
Comments
Likewise repeated element removal (via I'm largely just noting this here so that I can use the same ticket number in all of the FIXME notes I am adding a number to. :) |
#12884 is similar (although this issue is more general). |
Traige: |
Closing in favor of rust-lang/rfcs#1065 |
Derive block attributes from block item tree
The
Vec
type currently provides anpush
method that allows one to insert a single element at the end of the vector, as well aspush_all
andpush_all_move
methods that allow inserting many elements at the end of the vector more efficiently than would happen if the client code calledpush
in a loop (because it avoids repeatedly re-growing the vector).Vec
also offers aninsert
method that allows inserting a single element somewhere in the innards of the vector.I believe we could usefully add
insert_all
andinsert_all_move
methods that insert a sequence of elements at once. These methods would:Caveat: we would need to ensure that
fail!
does not occur between steps 2 and 3.Much like with
push_all
/push_all_move
, the advantage would be avoiding repeatedly re-growing the vector, the way that callinginsert
in a loop will do.(The
insert_all
andinsert_all_move
may have to have their own dedicated implementations, rather than being layed atop an iterator-based abstraction the way thatpush_all
/push_all_move
are atopExtendable::extend
, because of the caveat given above (we cannot call out to arbitrary iterator code during step 3 because we cannot allow failure while the vector is in an intermediate state where it has partially blank innards).I am filing this mostly as a note because while I was working on #15418, I found a potential need for methods like these to avoid quadratic asymptotic runtimes. But it is probably not a high priority.
The text was updated successfully, but these errors were encountered: