Skip to content

Commit

Permalink
Add O(1) Vec -> VecDeque conversion guarantee
Browse files Browse the repository at this point in the history
  • Loading branch information
Sp00ph committed Nov 29, 2022
1 parent 327b94a commit a06f7f8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2789,9 +2789,9 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
/// [`Vec<T>`]: crate::vec::Vec
/// [`VecDeque<T>`]: crate::collections::VecDeque
///
/// In its current implementation, this is a very cheap
/// conversion. This isn't yet a guarantee though, and
/// shouldn't be relied on.
/// This conversion is guaranteed to run in *O*(1) time
/// and to not re-allocate the `Vec`'s buffer or
/// allocate any additional memory.
fn from(other: Vec<T, A>) -> Self {
let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc();
Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } }
Expand Down

0 comments on commit a06f7f8

Please sign in to comment.