@@ -11,12 +11,10 @@ use std::{
1111 hash:: { Hash , Hasher } ,
1212 mem:: ManuallyDrop ,
1313 ops,
14- ptr:: NonNull ,
1514 slice:: SliceIndex ,
1615} ;
1716
18- use allocator_api2:: vec:: Vec as InnerVec ;
19- use bumpalo:: Bump ;
17+ use crate :: vec2:: Vec as InnerVec ;
2018#[ cfg( any( feature = "serialize" , test) ) ]
2119use oxc_estree:: { ESTree , Serializer as ESTreeSerializer } ;
2220#[ cfg( any( feature = "serialize" , test) ) ]
@@ -37,7 +35,7 @@ use crate::{Allocator, Box};
3735/// Static checks make this impossible to do. [`Vec::new_in`] and all other methods which create
3836/// a [`Vec`] will refuse to compile if called with a [`Drop`] type.
3937#[ derive( PartialEq , Eq ) ]
40- pub struct Vec < ' alloc , T > ( pub ( crate ) ManuallyDrop < InnerVec < T , & ' alloc Bump > > ) ;
38+ pub struct Vec < ' alloc , T > ( pub ( crate ) ManuallyDrop < InnerVec < ' alloc , T > > ) ;
4139
4240/// SAFETY: Not actually safe, but for enabling `Send` for downstream crates.
4341unsafe impl < T > Send for Vec < ' _ , T > { }
@@ -167,44 +165,10 @@ impl<'alloc, T> Vec<'alloc, T> {
167165 let vec = unsafe { InnerVec :: from_raw_parts_in ( ptr, N , N , allocator. bump ( ) ) } ;
168166 Self ( ManuallyDrop :: new ( vec) )
169167 }
170-
171- /// Converts the vector into [`Box<[T]>`][owned slice].
172- ///
173- /// Any excess capacity the vector has will not be included in the slice.
174- /// The excess memory will be leaked in the arena (i.e. not reused by another allocation).
175- ///
176- /// # Examples
177- /// ```
178- /// use oxc_allocator::{Allocator, Vec};
179- ///
180- /// let allocator = Allocator::default();
181- /// let mut v = Vec::with_capacity_in(10, &allocator);
182- /// v.extend([1, 2, 3]);
183- /// let b = v.into_boxed_slice();
184- ///
185- /// assert_eq!(&*b, &[1, 2, 3]);
186- /// assert_eq!(b.len(), 3);
187- /// ```
188- ///
189- /// [owned slice]: Box
190- #[ inline]
191- pub fn into_boxed_slice ( self ) -> Box < ' alloc , [ T ] > {
192- let inner = ManuallyDrop :: into_inner ( self . 0 ) ;
193- let slice = inner. leak ( ) ;
194- let ptr = NonNull :: from ( slice) ;
195- // SAFETY: `ptr` points to a valid slice `[T]`.
196- // `allocator_api2::vec::Vec::leak` consumes the inner `Vec` without dropping it.
197- // Lifetime of returned `Box<'alloc, [T]>` is same as lifetime of consumed `Vec<'alloc, T>`,
198- // so data in the `Box` must be valid for its lifetime.
199- // `Vec` uniquely owned the data, and we have consumed the `Vec`, so the new `Box` has
200- // unique ownership of the data (no aliasing).
201- // `ptr` was created from a `&mut [T]`.
202- unsafe { Box :: from_non_null ( ptr) }
203- }
204168}
205169
206170impl < ' alloc , T > ops:: Deref for Vec < ' alloc , T > {
207- type Target = InnerVec < T , & ' alloc Bump > ;
171+ type Target = InnerVec < ' alloc , T > ;
208172
209173 #[ inline]
210174 fn deref ( & self ) -> & Self :: Target {
@@ -214,13 +178,13 @@ impl<'alloc, T> ops::Deref for Vec<'alloc, T> {
214178
215179impl < ' alloc , T > ops:: DerefMut for Vec < ' alloc , T > {
216180 #[ inline]
217- fn deref_mut ( & mut self ) -> & mut InnerVec < T , & ' alloc Bump > {
181+ fn deref_mut ( & mut self ) -> & mut InnerVec < ' alloc , T > {
218182 & mut self . 0
219183 }
220184}
221185
222186impl < ' alloc , T > IntoIterator for Vec < ' alloc , T > {
223- type IntoIter = <InnerVec < T , & ' alloc Bump > as IntoIterator >:: IntoIter ;
187+ type IntoIter = <InnerVec < ' alloc , T > as IntoIterator >:: IntoIter ;
224188 type Item = T ;
225189
226190 #[ inline( always) ]
@@ -352,19 +316,4 @@ mod test {
352316 program
353317 }
354318 }
355-
356- #[ test]
357- fn vec_to_boxed_slice ( ) {
358- let allocator = Allocator :: default ( ) ;
359- let mut v = Vec :: with_capacity_in ( 10 , & allocator) ;
360- v. extend ( [ 1 , 2 , 3 ] ) ;
361-
362- let b = v. into_boxed_slice ( ) ;
363- // Check return value is an `oxc_allocator::Box`, not an `allocator_api2::boxed::Box`
364- let b: Box < [ u8 ] > = b;
365-
366- assert_eq ! ( & * b, & [ 1 , 2 , 3 ] ) ;
367- // Check length of slice is equal to what `v.len()` was, not `v.capacity()`
368- assert_eq ! ( b. len( ) , 3 ) ;
369- }
370319}
0 commit comments