@@ -17,9 +17,8 @@ use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1717
1818use serialize:: { self , Encodable , Encoder , Decodable , Decoder } ;
1919use syntax_pos:: { Span , DUMMY_SP } ;
20- use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
21- use rustc_data_structures:: array_vec:: ArrayVec ;
2220use rustc_data_structures:: indexed_vec:: Idx ;
21+ use smallvec:: SmallVec ;
2322
2423use core:: intrinsics;
2524use std:: cmp:: Ordering ;
@@ -203,11 +202,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
203202 {
204203 let defs = tcx. generics_of ( def_id) ;
205204 let count = defs. count ( ) ;
206- let mut substs = if count <= 8 {
207- AccumulateVec :: Array ( ArrayVec :: new ( ) )
208- } else {
209- AccumulateVec :: Heap ( Vec :: with_capacity ( count) )
210- } ;
205+ let mut substs = SmallVec :: with_capacity ( count) ;
211206 Substs :: fill_item ( & mut substs, tcx, defs, & mut mk_kind) ;
212207 tcx. intern_substs ( & substs)
213208 }
@@ -227,7 +222,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
227222 } )
228223 }
229224
230- fn fill_item < F > ( substs : & mut AccumulateVec < [ Kind < ' tcx > ; 8 ] > ,
225+ fn fill_item < F > ( substs : & mut SmallVec < [ Kind < ' tcx > ; 8 ] > ,
231226 tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
232227 defs : & ty:: Generics ,
233228 mk_kind : & mut F )
@@ -240,18 +235,15 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
240235 Substs :: fill_single ( substs, defs, mk_kind)
241236 }
242237
243- fn fill_single < F > ( substs : & mut AccumulateVec < [ Kind < ' tcx > ; 8 ] > ,
238+ fn fill_single < F > ( substs : & mut SmallVec < [ Kind < ' tcx > ; 8 ] > ,
244239 defs : & ty:: Generics ,
245240 mk_kind : & mut F )
246241 where F : FnMut ( & ty:: GenericParamDef , & [ Kind < ' tcx > ] ) -> Kind < ' tcx >
247242 {
248243 for param in & defs. params {
249244 let kind = mk_kind ( param, substs) ;
250245 assert_eq ! ( param. index as usize , substs. len( ) ) ;
251- match * substs {
252- AccumulateVec :: Array ( ref mut arr) => arr. push ( kind) ,
253- AccumulateVec :: Heap ( ref mut vec) => vec. push ( kind) ,
254- }
246+ substs. push ( kind) ;
255247 }
256248 }
257249
@@ -325,7 +317,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
325317
326318impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx Substs < ' tcx > {
327319 fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
328- let params: AccumulateVec < [ _ ; 8 ] > = self . iter ( ) . map ( |k| k. fold_with ( folder) ) . collect ( ) ;
320+ let params: SmallVec < [ _ ; 8 ] > = self . iter ( ) . map ( |k| k. fold_with ( folder) ) . collect ( ) ;
329321
330322 // If folding doesn't change the substs, it's faster to avoid
331323 // calling `mk_substs` and instead reuse the existing substs.
0 commit comments