@@ -726,6 +726,21 @@ impl<T> RawTable<T> {
726726 _marker : PhantomData ,
727727 }
728728 }
729+
730+ /// Converts the table into a raw allocation. The contents of the table
731+ /// should be dropped using a `RawIter` before freeing the allocation.
732+ #[ inline]
733+ pub fn into_alloc ( self ) -> Option < ( NonNull < u8 > , Layout ) > {
734+ let alloc = if self . bucket_mask != 0 {
735+ let ( layout, _) = calculate_layout :: < T > ( self . buckets ( ) )
736+ . unwrap_or_else ( || unsafe { hint:: unreachable_unchecked ( ) } ) ;
737+ Some ( ( self . ctrl . cast ( ) , layout) )
738+ } else {
739+ None
740+ } ;
741+ mem:: forget ( self ) ;
742+ alloc
743+ }
729744}
730745
731746unsafe impl < T > Send for RawTable < T > where T : Send { }
@@ -803,15 +818,8 @@ impl<T> IntoIterator for RawTable<T> {
803818 #[ inline]
804819 fn into_iter ( self ) -> RawIntoIter < T > {
805820 unsafe {
806- let alloc = if self . bucket_mask != 0 {
807- let ( layout, _) = calculate_layout :: < T > ( self . buckets ( ) )
808- . unwrap_or_else ( || hint:: unreachable_unchecked ( ) ) ;
809- Some ( ( self . ctrl . cast ( ) , layout) )
810- } else {
811- None
812- } ;
813821 let iter = self . iter ( ) ;
814- mem :: forget ( self ) ;
822+ let alloc = self . into_alloc ( ) ;
815823 RawIntoIter { iter, alloc }
816824 }
817825 }
@@ -832,11 +840,7 @@ impl<T> RawIterRange<T> {
832840 ///
833841 /// The start offset must be aligned to the group width.
834842 #[ inline]
835- unsafe fn new (
836- ctrl : * const u8 ,
837- data : * const T ,
838- range : Range < usize > ,
839- ) -> RawIterRange < T > {
843+ unsafe fn new ( ctrl : * const u8 , data : * const T , range : Range < usize > ) -> RawIterRange < T > {
840844 debug_assert_eq ! ( range. start % Group :: WIDTH , 0 ) ;
841845 let ctrl = ctrl. add ( range. start ) ;
842846 let data = data. add ( range. start ) ;
0 commit comments