@@ -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 > { }
@@ -168,43 +166,43 @@ impl<'alloc, T> Vec<'alloc, T> {
168166 Self ( ManuallyDrop :: new ( vec) )
169167 }
170168
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- }
169+ // // / Converts the vector into [`Box<[T]>`][owned slice].
170+ // // /
171+ // // / Any excess capacity the vector has will not be included in the slice.
172+ // // / The excess memory will be leaked in the arena (i.e. not reused by another allocation).
173+ // // /
174+ // // / # Examples
175+ // // / ```
176+ // // / use oxc_allocator::{Allocator, Vec};
177+ // // /
178+ // // / let allocator = Allocator::default();
179+ // // / let mut v = Vec::with_capacity_in(10, &allocator);
180+ // // / v.extend([1, 2, 3]);
181+ // // / let b = v.into_boxed_slice();
182+ // // /
183+ // // / assert_eq!(&*b, &[1, 2, 3]);
184+ // // / assert_eq!(b.len(), 3);
185+ // // / ```
186+ // // /
187+ // // / [owned slice]: Box
188+ // #[inline]
189+ // pub fn into_boxed_slice(self) -> Box<'alloc, [T]> {
190+ // let inner = ManuallyDrop::into_inner(self.0);
191+ // let slice = inner.leak();
192+ // let ptr = NonNull::from(slice);
193+ // // SAFETY: `ptr` points to a valid slice `[T]`.
194+ // // `allocator_api2::vec::Vec::leak` consumes the inner `Vec` without dropping it.
195+ // // Lifetime of returned `Box<'alloc, [T]>` is same as lifetime of consumed `Vec<'alloc, T>`,
196+ // // so data in the `Box` must be valid for its lifetime.
197+ // // `Vec` uniquely owned the data, and we have consumed the `Vec`, so the new `Box` has
198+ // // unique ownership of the data (no aliasing).
199+ // // `ptr` was created from a `&mut [T]`.
200+ // unsafe { Box::from_non_null(ptr) }
201+ // }
204202}
205203
206- impl < ' alloc , T > ops:: Deref for Vec < ' alloc , T > {
207- type Target = InnerVec < T , & ' alloc Bump > ;
204+ impl < ' alloc , T : ' alloc > ops:: Deref for Vec < ' alloc , T > {
205+ type Target = InnerVec < ' alloc , T > ;
208206
209207 #[ inline]
210208 fn deref ( & self ) -> & Self :: Target {
@@ -214,13 +212,13 @@ impl<'alloc, T> ops::Deref for Vec<'alloc, T> {
214212
215213impl < ' alloc , T > ops:: DerefMut for Vec < ' alloc , T > {
216214 #[ inline]
217- fn deref_mut ( & mut self ) -> & mut InnerVec < T , & ' alloc Bump > {
215+ fn deref_mut ( & mut self ) -> & mut InnerVec < ' alloc , T > {
218216 & mut self . 0
219217 }
220218}
221219
222220impl < ' alloc , T > IntoIterator for Vec < ' alloc , T > {
223- type IntoIter = <InnerVec < T , & ' alloc Bump > as IntoIterator >:: IntoIter ;
221+ type IntoIter = <InnerVec < ' alloc , T > as IntoIterator >:: IntoIter ;
224222 type Item = T ;
225223
226224 #[ inline( always) ]
@@ -353,18 +351,18 @@ mod test {
353351 }
354352 }
355353
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 ] ) ;
354+ // #[test]
355+ // fn vec_to_boxed_slice() {
356+ // let allocator = Allocator::default();
357+ // let mut v = Vec::with_capacity_in(10, &allocator);
358+ // v.extend([1, 2, 3]);
361359
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;
360+ // let b = v.into_boxed_slice();
361+ // // Check return value is an `oxc_allocator::Box`, not an `allocator_api2::boxed::Box`
362+ // let b: Box<[u8]> = b;
365363
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- }
364+ // assert_eq!(&*b, &[1, 2, 3]);
365+ // // Check length of slice is equal to what `v.len()` was, not `v.capacity()`
366+ // assert_eq!(b.len(), 3);
367+ // }
370368}
0 commit comments