@@ -5,13 +5,15 @@ use rustc_data_structures::graph::{self, GraphPredecessors, GraphSuccessors};
5
5
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
6
6
use rustc_index:: vec:: IndexVec ;
7
7
use rustc_serialize:: { Decodable , Decoder , Encodable , Encoder } ;
8
+ use smallvec:: SmallVec ;
8
9
use std:: iter;
9
10
use std:: ops:: { Deref , DerefMut , Index , IndexMut } ;
10
11
use std:: vec:: IntoIter ;
11
12
12
13
#[ derive( Clone , Debug ) ]
13
14
pub struct Cache {
14
- predecessors : Option < IndexVec < BasicBlock , Vec < BasicBlock > > > ,
15
+ // Typically 95%+ of the inner vectors have 4 or fewer elements.
16
+ predecessors : Option < IndexVec < BasicBlock , SmallVec < [ BasicBlock ; 4 ] > > > ,
15
17
}
16
18
17
19
impl rustc_serialize:: Encodable for Cache {
@@ -44,7 +46,7 @@ impl Cache {
44
46
45
47
pub fn ensure_predecessors ( & mut self , body : & Body < ' _ > ) {
46
48
if self . predecessors . is_none ( ) {
47
- let mut result = IndexVec :: from_elem ( vec ! [ ] , body. basic_blocks ( ) ) ;
49
+ let mut result = IndexVec :: from_elem ( smallvec ! [ ] , body. basic_blocks ( ) ) ;
48
50
for ( bb, data) in body. basic_blocks ( ) . iter_enumerated ( ) {
49
51
if let Some ( ref term) = data. terminator {
50
52
for & tgt in term. successors ( ) {
@@ -58,7 +60,11 @@ impl Cache {
58
60
}
59
61
60
62
/// This will recompute the predecessors cache if it is not available
61
- fn predecessors ( & mut self , body : & Body < ' _ > ) -> & IndexVec < BasicBlock , Vec < BasicBlock > > {
63
+ // njn: typedef?
64
+ fn predecessors (
65
+ & mut self ,
66
+ body : & Body < ' _ > ,
67
+ ) -> & IndexVec < BasicBlock , SmallVec < [ BasicBlock ; 4 ] > > {
62
68
self . ensure_predecessors ( body) ;
63
69
self . predecessors . as_ref ( ) . unwrap ( )
64
70
}
@@ -137,7 +143,7 @@ impl BodyAndCache<'tcx> {
137
143
self . cache . ensure_predecessors ( & self . body ) ;
138
144
}
139
145
140
- pub fn predecessors ( & mut self ) -> & IndexVec < BasicBlock , Vec < BasicBlock > > {
146
+ pub fn predecessors ( & mut self ) -> & IndexVec < BasicBlock , SmallVec < [ BasicBlock ; 4 ] > > {
141
147
self . cache . predecessors ( & self . body )
142
148
}
143
149
@@ -199,7 +205,7 @@ impl ReadOnlyBodyAndCache<'a, 'tcx> {
199
205
Self { body, cache }
200
206
}
201
207
202
- pub fn predecessors ( & self ) -> & IndexVec < BasicBlock , Vec < BasicBlock > > {
208
+ pub fn predecessors ( & self ) -> & IndexVec < BasicBlock , SmallVec < [ BasicBlock ; 4 ] > > {
203
209
self . cache . predecessors . as_ref ( ) . unwrap ( )
204
210
}
205
211
0 commit comments