add specialization for extend_front and prepend with copied slice iterator

This commit is contained in:
Antoni Spaanderman 2025-11-03 12:35:30 +01:00
parent e23c1551a7
commit 5b96677adb
No known key found for this signature in database
GPG key ID: AE0B68E552E5DF8C
6 changed files with 117 additions and 33 deletions

View file

@ -20,6 +20,7 @@
#![feature(assert_matches)]
#![feature(char_internals)]
#![feature(char_max_len)]
#![feature(copied_into_inner)]
#![feature(core_intrinsics)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
@ -32,6 +33,7 @@
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(ptr_alignment_type)]
#![feature(ptr_internals)]
#![feature(rev_into_inner)]
#![feature(sized_type_properties)]
#![feature(slice_iter_mut_as_mut_slice)]
#![feature(slice_ptr_get)]

View file

@ -2113,14 +2113,45 @@ fn test_extend_front() {
}
#[test]
fn test_extend_front_specialization() {
fn test_extend_front_specialization_vec_into_iter() {
// trigger 4 code paths: all combinations of prepend and extend_front, wrap and no wrap
let mut v = VecDeque::with_capacity(4);
v.prepend(vec![1, 2, 3]);
assert_eq!(v, [1, 2, 3]);
v.pop_front();
v.prepend((-4..2).collect::<Vec<_>>());
assert_eq!(v, (-4..=3).collect::<Vec<_>>());
v.clear();
v.pop_back();
// this should wrap around the physical buffer
v.prepend(vec![-1, 0]);
// check it really wrapped
assert_eq!(v.as_slices(), ([-1].as_slice(), [0, 1, 2].as_slice()));
let mut v = VecDeque::with_capacity(4);
v.extend_front(vec![1, 2, 3]);
assert_eq!(v, [3, 2, 1]);
v.pop_back();
// this should wrap around the physical buffer
v.extend_front(vec![4, 5]);
// check it really wrapped
assert_eq!(v.as_slices(), ([5].as_slice(), [4, 3, 2].as_slice()));
}
#[test]
fn test_extend_front_specialization_copy_slice() {
// trigger 4 code paths: all combinations of prepend and extend_front, wrap and no wrap
let mut v = VecDeque::with_capacity(4);
v.prepend([1, 2, 3].as_slice().iter().copied());
assert_eq!(v, [1, 2, 3]);
v.pop_back();
// this should wrap around the physical buffer
v.prepend([-1, 0].as_slice().iter().copied());
// check it really wrapped
assert_eq!(v.as_slices(), ([-1].as_slice(), [0, 1, 2].as_slice()));
let mut v = VecDeque::with_capacity(4);
v.extend_front([1, 2, 3].as_slice().iter().copied());
assert_eq!(v, [3, 2, 1]);
v.pop_back();
// this should wrap around the physical buffer
v.extend_front([4, 5].as_slice().iter().copied());
// check it really wrapped
assert_eq!(v.as_slices(), ([5].as_slice(), [4, 3, 2].as_slice()));
}