1
1
use crate :: mir:: interpret:: Scalar ;
2
2
use crate :: ty:: { self , Ty , TyCtxt } ;
3
3
use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
4
+ use smallvec:: { smallvec, SmallVec } ;
4
5
5
6
use super :: {
6
7
AssertMessage , BasicBlock , InlineAsmOperand , Operand , Place , SourceInfo , Successors ,
@@ -17,10 +18,10 @@ use std::slice;
17
18
pub use super :: query:: * ;
18
19
19
20
#[ derive( Debug , Clone , TyEncodable , TyDecodable , HashStable , PartialEq ) ]
20
- pub struct SwitchTargets < ' tcx > {
21
+ pub struct SwitchTargets {
21
22
/// Possible values. The locations to branch to in each case
22
23
/// are found in the corresponding indices from the `targets` vector.
23
- values : Cow < ' tcx , [ u128 ] > ,
24
+ values : SmallVec < [ u128 ; 1 ] > ,
24
25
25
26
/// Possible branch sites. The last element of this vector is used
26
27
/// for the otherwise branch, so targets.len() == values.len() + 1
@@ -34,24 +35,24 @@ pub struct SwitchTargets<'tcx> {
34
35
//
35
36
// However we’ve decided to keep this as-is until we figure a case
36
37
// where some other approach seems to be strictly better than other.
37
- targets : Vec < BasicBlock > ,
38
+ targets : SmallVec < [ BasicBlock ; 2 ] > ,
38
39
}
39
40
40
- impl < ' tcx > SwitchTargets < ' tcx > {
41
+ impl SwitchTargets {
41
42
/// Creates switch targets from an iterator of values and target blocks.
42
43
///
43
44
/// The iterator may be empty, in which case the `SwitchInt` instruction is equivalent to
44
45
/// `goto otherwise;`.
45
46
pub fn new ( targets : impl Iterator < Item = ( u128 , BasicBlock ) > , otherwise : BasicBlock ) -> Self {
46
- let ( values, mut targets) : ( Vec < _ > , Vec < _ > ) = targets. unzip ( ) ;
47
+ let ( values, mut targets) : ( SmallVec < _ > , SmallVec < _ > ) = targets. unzip ( ) ;
47
48
targets. push ( otherwise) ;
48
49
Self { values : values. into ( ) , targets }
49
50
}
50
51
51
52
/// Builds a switch targets definition that jumps to `then` if the tested value equals `value`,
52
53
/// and to `else_` if not.
53
- pub fn static_if ( value : & ' static [ u128 ; 1 ] , then : BasicBlock , else_ : BasicBlock ) -> Self {
54
- Self { values : Cow :: Borrowed ( value) , targets : vec ! [ then, else_] }
54
+ pub fn static_if ( value : u128 , then : BasicBlock , else_ : BasicBlock ) -> Self {
55
+ Self { values : smallvec ! [ value] , targets : smallvec ! [ then, else_] }
55
56
}
56
57
57
58
/// Returns the fallback target that is jumped to when none of the values match the operand.
@@ -113,7 +114,7 @@ pub enum TerminatorKind<'tcx> {
113
114
/// FIXME: remove this redundant information. Currently, it is relied on by pretty-printing.
114
115
switch_ty : Ty < ' tcx > ,
115
116
116
- targets : SwitchTargets < ' tcx > ,
117
+ targets : SwitchTargets ,
117
118
} ,
118
119
119
120
/// Indicates that the landing pad is finished and unwinding should
@@ -295,7 +296,7 @@ impl<'tcx> TerminatorKind<'tcx> {
295
296
TerminatorKind :: SwitchInt {
296
297
discr : cond,
297
298
switch_ty : tcx. types . bool ,
298
- targets : SwitchTargets :: static_if ( & [ 0 ] , f, t) ,
299
+ targets : SwitchTargets :: static_if ( 0 , f, t) ,
299
300
}
300
301
}
301
302
0 commit comments