@@ -10,6 +10,7 @@ use rustc_middle::ty::{self, Ty, TypeFoldable};
1010use rustc_target:: abi:: { Abi , AddressSpace , Align , FieldsShape } ;
1111use rustc_target:: abi:: { Int , Pointer , F32 , F64 } ;
1212use rustc_target:: abi:: { LayoutOf , PointeeInfo , Scalar , Size , TyAndLayoutMethods , Variants } ;
13+ use smallvec:: { smallvec, SmallVec } ;
1314use tracing:: debug;
1415
1516use std:: fmt:: Write ;
@@ -18,7 +19,7 @@ fn uncached_llvm_type<'a, 'tcx>(
1819 cx : & CodegenCx < ' a , ' tcx > ,
1920 layout : TyAndLayout < ' tcx > ,
2021 defer : & mut Option < ( & ' a Type , TyAndLayout < ' tcx > ) > ,
21- field_remapping : & mut Option < Box < [ u32 ] > > ,
22+ field_remapping : & mut Option < Box < SmallVec < [ u32 ; 4 ] > > > ,
2223) -> & ' a Type {
2324 match layout. abi {
2425 Abi :: Scalar ( _) => bug ! ( "handled elsewhere" ) ,
@@ -93,15 +94,15 @@ fn uncached_llvm_type<'a, 'tcx>(
9394fn struct_llfields < ' a , ' tcx > (
9495 cx : & CodegenCx < ' a , ' tcx > ,
9596 layout : TyAndLayout < ' tcx > ,
96- ) -> ( Vec < & ' a Type > , bool , Option < Box < [ u32 ] > > ) {
97+ ) -> ( Vec < & ' a Type > , bool , Option < Box < SmallVec < [ u32 ; 4 ] > > > ) {
9798 debug ! ( "struct_llfields: {:#?}" , layout) ;
9899 let field_count = layout. fields . count ( ) ;
99100
100101 let mut packed = false ;
101102 let mut offset = Size :: ZERO ;
102103 let mut prev_effective_align = layout. align . abi ;
103104 let mut result: Vec < _ > = Vec :: with_capacity ( 1 + field_count * 2 ) ;
104- let mut field_remapping = vec ! [ 0 ; field_count] ;
105+ let mut field_remapping = smallvec ! [ 0 ; field_count] ;
105106 for i in layout. fields . index_by_increasing_offset ( ) {
106107 let target_offset = layout. fields . offset ( i as usize ) ;
107108 let field = layout. field ( cx, i) ;
@@ -150,7 +151,7 @@ fn struct_llfields<'a, 'tcx>(
150151 debug ! ( "struct_llfields: offset: {:?} stride: {:?}" , offset, layout. size) ;
151152 }
152153
153- ( result, packed, padding_used. then_some ( field_remapping . into_boxed_slice ( ) ) )
154+ ( result, packed, padding_used. then_some ( Box :: new ( field_remapping ) ) )
154155}
155156
156157impl < ' a , ' tcx > CodegenCx < ' a , ' tcx > {
0 commit comments