@@ -41,8 +41,10 @@ pub struct TypeFreshener<'a, 'tcx> {
41
41
infcx : & ' a InferCtxt < ' tcx > ,
42
42
ty_freshen_count : u32 ,
43
43
const_freshen_count : u32 ,
44
- ty_freshen_map : FxHashMap < ty:: InferTy , Ty < ' tcx > > ,
45
- const_freshen_map : FxHashMap < ty:: InferConst , ty:: Const < ' tcx > > ,
44
+ ty_freshen_key_vec : Vec < ty:: InferTy > ,
45
+ ty_freshen_value_vec : Vec < Ty < ' tcx > > ,
46
+ const_freshen_key_vec : Vec < ty:: InferConst > ,
47
+ const_freshen_value_vec : Vec < ty:: Const < ' tcx > > ,
46
48
}
47
49
48
50
impl < ' a , ' tcx > TypeFreshener < ' a , ' tcx > {
@@ -51,8 +53,10 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
51
53
infcx,
52
54
ty_freshen_count : 0 ,
53
55
const_freshen_count : 0 ,
54
- ty_freshen_map : Default :: default ( ) ,
55
- const_freshen_map : Default :: default ( ) ,
56
+ ty_freshen_key_vec : Vec :: new ( ) ,
57
+ ty_freshen_value_vec : Vec :: new ( ) ,
58
+ const_freshen_key_vec : Vec :: new ( ) ,
59
+ const_freshen_value_vec : Vec :: new ( ) ,
56
60
}
57
61
}
58
62
@@ -64,15 +68,15 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
64
68
return ty. fold_with ( self ) ;
65
69
}
66
70
67
- match self . ty_freshen_map . entry ( key) {
68
- Entry :: Occupied ( entry ) => * entry . get ( ) ,
69
- Entry :: Vacant ( entry ) => {
70
- let index = self . ty_freshen_count ;
71
- self . ty_freshen_count += 1 ;
72
- let t = mk_fresh ( index) ;
73
- entry . insert ( t ) ;
74
- t
75
- }
71
+ if let Some ( idx ) = self . ty_freshen_key_vec . iter ( ) . position ( |infty| * infty == key) {
72
+ unsafe { self . ty_freshen_value_vec [ idx ] }
73
+ } else {
74
+ let index = self . ty_freshen_count ;
75
+ self . ty_freshen_count += 1 ;
76
+ let t = mk_fresh ( index) ;
77
+ self . ty_freshen_key_vec . push ( key ) ;
78
+ self . ty_freshen_value_vec . push ( t ) ;
79
+ t
76
80
}
77
81
}
78
82
@@ -90,15 +94,15 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
90
94
return ct. fold_with ( self ) ;
91
95
}
92
96
93
- match self . const_freshen_map . entry ( key) {
94
- Entry :: Occupied ( entry ) => * entry . get ( ) ,
95
- Entry :: Vacant ( entry ) => {
96
- let index = self . const_freshen_count ;
97
- self . const_freshen_count += 1 ;
98
- let ct = ty:: Const :: new_infer ( self . infcx . tcx , freshener ( index) , ty) ;
99
- entry . insert ( ct ) ;
100
- ct
101
- }
97
+ if let Some ( idx ) = self . const_freshen_key_vec . iter ( ) . position ( |infty| * infty == key) {
98
+ unsafe { self . const_freshen_value_vec [ idx ] }
99
+ } else {
100
+ let index: u32 = self . const_freshen_count ;
101
+ self . const_freshen_count += 1 ;
102
+ let ct = ty:: Const :: new_infer ( self . infcx . tcx , freshener ( index) , ty) ;
103
+ self . const_freshen_key_vec . push ( key ) ;
104
+ self . const_freshen_value_vec . push ( ct ) ;
105
+ ct
102
106
}
103
107
}
104
108
}
0 commit comments