@@ -17,9 +17,8 @@ use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
17
17
18
18
use serialize:: { self , Encodable , Encoder , Decodable , Decoder } ;
19
19
use syntax_pos:: { Span , DUMMY_SP } ;
20
- use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
21
- use rustc_data_structures:: array_vec:: ArrayVec ;
22
20
use rustc_data_structures:: indexed_vec:: Idx ;
21
+ use smallvec:: SmallVec ;
23
22
24
23
use core:: intrinsics;
25
24
use std:: cmp:: Ordering ;
@@ -203,11 +202,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
203
202
{
204
203
let defs = tcx. generics_of ( def_id) ;
205
204
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) ;
211
206
Substs :: fill_item ( & mut substs, tcx, defs, & mut mk_kind) ;
212
207
tcx. intern_substs ( & substs)
213
208
}
@@ -227,7 +222,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
227
222
} )
228
223
}
229
224
230
- fn fill_item < F > ( substs : & mut AccumulateVec < [ Kind < ' tcx > ; 8 ] > ,
225
+ fn fill_item < F > ( substs : & mut SmallVec < [ Kind < ' tcx > ; 8 ] > ,
231
226
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
232
227
defs : & ty:: Generics ,
233
228
mk_kind : & mut F )
@@ -240,18 +235,15 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
240
235
Substs :: fill_single ( substs, defs, mk_kind)
241
236
}
242
237
243
- fn fill_single < F > ( substs : & mut AccumulateVec < [ Kind < ' tcx > ; 8 ] > ,
238
+ fn fill_single < F > ( substs : & mut SmallVec < [ Kind < ' tcx > ; 8 ] > ,
244
239
defs : & ty:: Generics ,
245
240
mk_kind : & mut F )
246
241
where F : FnMut ( & ty:: GenericParamDef , & [ Kind < ' tcx > ] ) -> Kind < ' tcx >
247
242
{
248
243
for param in & defs. params {
249
244
let kind = mk_kind ( param, substs) ;
250
245
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) ;
255
247
}
256
248
}
257
249
@@ -325,7 +317,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
325
317
326
318
impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx Substs < ' tcx > {
327
319
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 ( ) ;
329
321
330
322
// If folding doesn't change the substs, it's faster to avoid
331
323
// calling `mk_substs` and instead reuse the existing substs.
0 commit comments