@@ -17,6 +17,8 @@ use std::mem;
17
17
18
18
use rustc_data_structures:: fx:: FxHashMap ;
19
19
20
+ use crate :: helpers:: ToUsize ;
21
+
20
22
/// Intermediate key between a UniKeyMap and a UniValMap.
21
23
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
22
24
pub struct UniIndex {
@@ -158,7 +160,7 @@ where
158
160
impl < V > UniValMap < V > {
159
161
/// Whether this index has an associated value.
160
162
pub fn contains_idx ( & self , idx : UniIndex ) -> bool {
161
- self . data . get ( idx. idx as usize ) . and_then ( Option :: as_ref) . is_some ( )
163
+ self . data . get ( idx. idx . to_usize ( ) ) . and_then ( Option :: as_ref) . is_some ( )
162
164
}
163
165
164
166
/// Reserve enough space to insert the value at the right index.
@@ -174,29 +176,29 @@ impl<V> UniValMap<V> {
174
176
175
177
/// Assign a value to the index. Permanently overwrites any previous value.
176
178
pub fn insert ( & mut self , idx : UniIndex , val : V ) {
177
- self . extend_to_length ( idx. idx as usize + 1 ) ;
178
- self . data [ idx. idx as usize ] = Some ( val)
179
+ self . extend_to_length ( idx. idx . to_usize ( ) + 1 ) ;
180
+ self . data [ idx. idx . to_usize ( ) ] = Some ( val)
179
181
}
180
182
181
183
/// Get the value at this index, if it exists.
182
184
pub fn get ( & self , idx : UniIndex ) -> Option < & V > {
183
- self . data . get ( idx. idx as usize ) . and_then ( Option :: as_ref)
185
+ self . data . get ( idx. idx . to_usize ( ) ) . and_then ( Option :: as_ref)
184
186
}
185
187
186
188
/// Get the value at this index mutably, if it exists.
187
189
pub fn get_mut ( & mut self , idx : UniIndex ) -> Option < & mut V > {
188
- self . data . get_mut ( idx. idx as usize ) . and_then ( Option :: as_mut)
190
+ self . data . get_mut ( idx. idx . to_usize ( ) ) . and_then ( Option :: as_mut)
189
191
}
190
192
191
193
/// Delete any value associated with this index.
192
194
/// Returns None if the value was not present, otherwise
193
195
/// returns the previously stored value.
194
196
pub fn remove ( & mut self , idx : UniIndex ) -> Option < V > {
195
- if idx. idx as usize >= self . data . len ( ) {
197
+ if idx. idx . to_usize ( ) >= self . data . len ( ) {
196
198
return None ;
197
199
}
198
200
let mut res = None ;
199
- mem:: swap ( & mut res, & mut self . data [ idx. idx as usize ] ) ;
201
+ mem:: swap ( & mut res, & mut self . data [ idx. idx . to_usize ( ) ] ) ;
200
202
res
201
203
}
202
204
}
@@ -209,8 +211,8 @@ pub struct UniEntry<'a, V> {
209
211
impl < ' a , V > UniValMap < V > {
210
212
/// Get a wrapper around a mutable access to the value corresponding to `idx`.
211
213
pub fn entry ( & ' a mut self , idx : UniIndex ) -> UniEntry < ' a , V > {
212
- self . extend_to_length ( idx. idx as usize + 1 ) ;
213
- UniEntry { inner : & mut self . data [ idx. idx as usize ] }
214
+ self . extend_to_length ( idx. idx . to_usize ( ) + 1 ) ;
215
+ UniEntry { inner : & mut self . data [ idx. idx . to_usize ( ) ] }
214
216
}
215
217
}
216
218
0 commit comments