@@ -17,6 +17,8 @@ use std::mem;
1717
1818use rustc_data_structures:: fx:: FxHashMap ;
1919
20+ use crate :: helpers:: ToUsize ;
21+
2022/// Intermediate key between a UniKeyMap and a UniValMap.
2123#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
2224pub struct UniIndex {
@@ -158,7 +160,7 @@ where
158160impl < V > UniValMap < V > {
159161 /// Whether this index has an associated value.
160162 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 ( )
162164 }
163165
164166 /// Reserve enough space to insert the value at the right index.
@@ -174,29 +176,29 @@ impl<V> UniValMap<V> {
174176
175177 /// Assign a value to the index. Permanently overwrites any previous value.
176178 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)
179181 }
180182
181183 /// Get the value at this index, if it exists.
182184 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)
184186 }
185187
186188 /// Get the value at this index mutably, if it exists.
187189 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)
189191 }
190192
191193 /// Delete any value associated with this index.
192194 /// Returns None if the value was not present, otherwise
193195 /// returns the previously stored value.
194196 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 ( ) {
196198 return None ;
197199 }
198200 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 ( ) ] ) ;
200202 res
201203 }
202204}
@@ -209,8 +211,8 @@ pub struct UniEntry<'a, V> {
209211impl < ' a , V > UniValMap < V > {
210212 /// Get a wrapper around a mutable access to the value corresponding to `idx`.
211213 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 ( ) ] }
214216 }
215217}
216218
0 commit comments