Skip to content

Commit dda7025

Browse files
committed
feat(allocator): remove drop operations from Vec2
1 parent 5cc614a commit dda7025

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

crates/oxc_allocator/src/vec2/mod.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ impl<'bump, T: 'bump> Vec<'bump, T> {
870870
unsafe {
871871
let ptr = self.as_ptr();
872872
let len = self.len();
873-
mem::forget(self);
873+
// Don't need `mem::forget(self)` here, because `Vec` does not implement `Drop`.
874874
slice::from_raw_parts(ptr, len)
875875
}
876876
}
@@ -895,7 +895,7 @@ impl<'bump, T: 'bump> Vec<'bump, T> {
895895
pub fn into_bump_slice_mut(mut self) -> &'bump mut [T] {
896896
let ptr = self.as_mut_ptr();
897897
let len = self.len();
898-
mem::forget(self);
898+
// Don't need `mem::forget(self)` here, because `Vec` does not implement `Drop`.
899899

900900
unsafe { slice::from_raw_parts_mut(ptr, len) }
901901
}
@@ -2244,7 +2244,7 @@ impl<'bump, T: 'bump> IntoIterator for Vec<'bump, T> {
22442244
} else {
22452245
begin.add(self.len()) as *const T
22462246
};
2247-
mem::forget(self);
2247+
// Don't need `mem::forget(self)` here, because `Vec` does not implement `Drop`.
22482248
IntoIter { phantom: PhantomData, ptr: begin, end }
22492249
}
22502250
}
@@ -2453,18 +2453,6 @@ impl<'bump, T: 'bump> BorrowMut<[T]> for Vec<'bump, T> {
24532453
}
24542454
}
24552455

2456-
impl<'bump, T> Drop for Vec<'bump, T> {
2457-
fn drop(&mut self) {
2458-
unsafe {
2459-
// use drop for [T]
2460-
// use a raw slice to refer to the elements of the vector as weakest necessary type;
2461-
// could avoid questions of validity in certain cases
2462-
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.as_mut_ptr(), self.len))
2463-
}
2464-
// RawVec handles deallocation
2465-
}
2466-
}
2467-
24682456
////////////////////////////////////////////////////////////////////////////////
24692457
// Clone-on-write
24702458
////////////////////////////////////////////////////////////////////////////////

crates/oxc_allocator/src/vec2/raw_vec.rs

-9
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,6 @@ impl<'a, T> RawVec<'a, T> {
702702
}
703703
}
704704

705-
impl<'a, T> Drop for RawVec<'a, T> {
706-
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
707-
fn drop(&mut self) {
708-
unsafe {
709-
self.dealloc_buffer();
710-
}
711-
}
712-
}
713-
714705
// We need to guarantee the following:
715706
// * We don't ever allocate `> isize::MAX` byte-size objects
716707
// * We don't overflow `usize::MAX` and actually allocate too little

0 commit comments

Comments
 (0)