Rollup merge of #105128 - Sp00ph:vec_vec_deque_conversion, r=dtolnay

Add O(1) `Vec -> VecDeque` conversion guarantee

(See #105072)
This commit is contained in:
Matthias Krüger 2023-01-07 20:43:20 +01:00 committed by GitHub
commit d7519c3639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2821,9 +2821,9 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
/// [`Vec<T>`]: crate::vec::Vec /// [`Vec<T>`]: crate::vec::Vec
/// [`VecDeque<T>`]: crate::collections::VecDeque /// [`VecDeque<T>`]: crate::collections::VecDeque
/// ///
/// In its current implementation, this is a very cheap /// This conversion is guaranteed to run in *O*(1) time
/// conversion. This isn't yet a guarantee though, and /// and to not re-allocate the `Vec`'s buffer or allocate
/// shouldn't be relied on. /// any additional memory.
#[inline] #[inline]
fn from(other: Vec<T, A>) -> Self { fn from(other: Vec<T, A>) -> Self {
let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc();