]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/src/collections/vec_deque/mod.rs
Rollup merge of #88452 - xu-cheng:vecdeque-from-array, r=m-ou-se
[rust.git] / library / alloc / src / collections / vec_deque / mod.rs
index 4a2b0b33bf2b2b1c3074c798fbbaafdfa8fcaa3d..007548ad1ab58d94dc7b7308223a65e48705d442 100644 (file)
@@ -3004,6 +3004,16 @@ fn from(mut other: VecDeque<T, A>) -> Self {
     /// assert_eq!(deq1, deq2);
     /// ```
     fn from(arr: [T; N]) -> Self {
-        core::array::IntoIter::new(arr).collect()
+        let mut deq = VecDeque::with_capacity(N);
+        let arr = ManuallyDrop::new(arr);
+        if mem::size_of::<T>() != 0 {
+            // SAFETY: VecDeque::with_capacity ensures that there is enough capacity.
+            unsafe {
+                ptr::copy_nonoverlapping(arr.as_ptr(), deq.ptr(), N);
+            }
+        }
+        deq.tail = 0;
+        deq.head = N;
+        deq
     }
 }