@@ -31,13 +31,11 @@ use super::unify_key::replace_if_possible;
31
31
use super :: unify_key:: { ConstVarValue , ConstVariableValue } ;
32
32
use super :: unify_key:: { ConstVariableOrigin , ConstVariableOriginKind } ;
33
33
use super :: { InferCtxt , MiscVariable , TypeTrace } ;
34
- use arrayvec:: ArrayVec ;
35
- use rustc_data_structures:: fx:: FxHashMap ;
36
- use std:: hash:: Hash ;
37
34
38
35
use crate :: traits:: { Obligation , PredicateObligations } ;
39
36
40
37
use rustc_ast as ast;
38
+ use rustc_data_structures:: mini_map:: MiniMap ;
41
39
use rustc_hir:: def_id:: DefId ;
42
40
use rustc_middle:: traits:: ObligationCause ;
43
41
use rustc_middle:: ty:: error:: TypeError ;
@@ -47,63 +45,6 @@ use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
47
45
use rustc_middle:: ty:: { IntType , UintType } ;
48
46
use rustc_span:: { Span , DUMMY_SP } ;
49
47
50
- /// Small-storage-optimized implementation of a map
51
- /// made specifically for caching results.
52
- ///
53
- /// Stores elements in a small array up to a certain length
54
- /// and switches to `HashMap` when that length is exceeded.
55
- enum MiniMap < K , V > {
56
- Array ( ArrayVec < [ ( K , V ) ; 8 ] > ) ,
57
- Map ( FxHashMap < K , V > ) ,
58
- }
59
-
60
- impl < K : Eq + Hash , V > MiniMap < K , V > {
61
- /// Creates an empty `MiniMap`.
62
- pub fn new ( ) -> Self {
63
- MiniMap :: Array ( ArrayVec :: new ( ) )
64
- }
65
-
66
- /// Inserts or updates value in the map.
67
- pub fn insert ( & mut self , key : K , value : V ) {
68
- match self {
69
- MiniMap :: Array ( array) => {
70
- for pair in array. iter_mut ( ) {
71
- if pair. 0 == key {
72
- pair. 1 = value;
73
- return ;
74
- }
75
- }
76
- if let Err ( error) = array. try_push ( ( key, value) ) {
77
- let mut map: FxHashMap < K , V > = array. drain ( ..) . collect ( ) ;
78
- let ( key, value) = error. element ( ) ;
79
- map. insert ( key, value) ;
80
- * self = MiniMap :: Map ( map) ;
81
- }
82
- }
83
- MiniMap :: Map ( map) => {
84
- map. insert ( key, value) ;
85
- }
86
- }
87
- }
88
-
89
- /// Return value by key if any.
90
- pub fn get ( & self , key : & K ) -> Option < & V > {
91
- match self {
92
- MiniMap :: Array ( array) => {
93
- for pair in array {
94
- if pair. 0 == * key {
95
- return Some ( & pair. 1 ) ;
96
- }
97
- }
98
- return None ;
99
- }
100
- MiniMap :: Map ( map) => {
101
- return map. get ( key) ;
102
- }
103
- }
104
- }
105
- }
106
-
107
48
#[ derive( Clone ) ]
108
49
pub struct CombineFields < ' infcx , ' tcx > {
109
50
pub infcx : & ' infcx InferCtxt < ' infcx , ' tcx > ,
0 commit comments