Skip to content

Commit becc24a

Browse files
committed
Auto merge of #97870 - eggyal:inplace_fold_spec, r=wesleywiser
Use liballoc's specialised in-place vec collection liballoc already specialises in-place vector collection, so manually reimplementing it in `IdFunctor::try_map_id` was superfluous.
2 parents ff0ffda + 9208c08 commit becc24a

File tree

1 file changed

+2
-34
lines changed

1 file changed

+2
-34
lines changed

compiler/rustc_data_structures/src/functor.rs

+2-34
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,11 @@ impl<T> IdFunctor for Vec<T> {
3434
type Inner = T;
3535

3636
#[inline]
37-
fn try_map_id<F, E>(self, mut f: F) -> Result<Self, E>
37+
fn try_map_id<F, E>(self, f: F) -> Result<Self, E>
3838
where
3939
F: FnMut(Self::Inner) -> Result<Self::Inner, E>,
4040
{
41-
struct HoleVec<T> {
42-
vec: Vec<mem::ManuallyDrop<T>>,
43-
hole: Option<usize>,
44-
}
45-
46-
impl<T> Drop for HoleVec<T> {
47-
fn drop(&mut self) {
48-
unsafe {
49-
for (index, slot) in self.vec.iter_mut().enumerate() {
50-
if self.hole != Some(index) {
51-
mem::ManuallyDrop::drop(slot);
52-
}
53-
}
54-
}
55-
}
56-
}
57-
58-
unsafe {
59-
let (ptr, length, capacity) = self.into_raw_parts();
60-
let vec = Vec::from_raw_parts(ptr.cast(), length, capacity);
61-
let mut hole_vec = HoleVec { vec, hole: None };
62-
63-
for (index, slot) in hole_vec.vec.iter_mut().enumerate() {
64-
hole_vec.hole = Some(index);
65-
let original = mem::ManuallyDrop::take(slot);
66-
let mapped = f(original)?;
67-
*slot = mem::ManuallyDrop::new(mapped);
68-
hole_vec.hole = None;
69-
}
70-
71-
mem::forget(hole_vec);
72-
Ok(Vec::from_raw_parts(ptr, length, capacity))
73-
}
41+
self.into_iter().map(f).collect()
7442
}
7543
}
7644

0 commit comments

Comments
 (0)