@@ -108,11 +108,12 @@ impl<K: DictionaryKey, M: MutableArray> ValueMap<K, M> {
108
108
// safety: we only iterate within bounds
109
109
let value = unsafe { values. value_unchecked_at ( index) } ;
110
110
let hash = ahash_hash ( value. borrow ( ) ) ;
111
- match map. raw_entry_mut ( ) . from_hash ( hash, |item| {
111
+ let entry = map. raw_entry_mut ( ) . from_hash ( hash, |item| {
112
112
// safety: invariant of the struct, it's always in bounds since we maintain it
113
113
let stored_value = unsafe { values. value_unchecked_at ( item. key . as_usize ( ) ) } ;
114
114
stored_value. borrow ( ) == value. borrow ( )
115
- } ) {
115
+ } ) ;
116
+ match entry {
116
117
RawEntryMut :: Occupied ( _) => {
117
118
return Err ( Error :: InvalidArgumentError (
118
119
"duplicate value in dictionary values array" . into ( ) ,
@@ -158,25 +159,25 @@ impl<K: DictionaryKey, M: MutableArray> ValueMap<K, M> {
158
159
M :: Type : Eq + Hash ,
159
160
{
160
161
let hash = ahash_hash ( value. as_indexed ( ) ) ;
161
- Ok (
162
- match self . map . raw_entry_mut ( ) . from_hash ( hash , |item| {
163
- // safety: we've already checked (the inverse) when we pushed it, so it should be ok?
164
- let index = unsafe { item . key . as_usize ( ) } ;
165
- // safety: invariant of the struct, it's always in bounds since we maintain it
166
- let stored_value = unsafe { self . values . value_unchecked_at ( index ) } ;
167
- stored_value . borrow ( ) == value . as_indexed ( )
168
- } ) {
169
- RawEntryMut :: Occupied ( entry) => entry. key ( ) . key ,
170
- RawEntryMut :: Vacant ( entry) => {
171
- let index = self . values . len ( ) ;
172
- let key = K :: try_from ( index) . map_err ( |_| Error :: Overflow ) ?;
173
- entry. insert_hashed_nocheck ( hash, Hashed { hash, key } , ( ) ) ; // NB: don't use .insert() here!
174
- push ( & mut self . values , value) ?;
175
- debug_assert_eq ! ( self . values. len( ) , index + 1 ) ;
176
- key
177
- }
178
- } ,
179
- )
162
+ let entry = self . map . raw_entry_mut ( ) . from_hash ( hash , |item| {
163
+ // safety: we've already checked (the inverse) when we pushed it, so it should be ok?
164
+ let index = unsafe { item . key . as_usize ( ) } ;
165
+ // safety: invariant of the struct, it's always in bounds since we maintain it
166
+ let stored_value = unsafe { self . values . value_unchecked_at ( index ) } ;
167
+ stored_value. borrow ( ) == value . as_indexed ( )
168
+ } ) ;
169
+ let result = match entry {
170
+ RawEntryMut :: Occupied ( entry) => entry. key ( ) . key ,
171
+ RawEntryMut :: Vacant ( entry) => {
172
+ let index = self . values . len ( ) ;
173
+ let key = K :: try_from ( index) . map_err ( |_| Error :: Overflow ) ?;
174
+ entry. insert_hashed_nocheck ( hash, Hashed { hash, key } , ( ) ) ; // NB: don't use .insert() here!
175
+ push ( & mut self . values , value) ?;
176
+ debug_assert_eq ! ( self . values. len( ) , index + 1 ) ;
177
+ key
178
+ }
179
+ } ;
180
+ Ok ( result )
180
181
}
181
182
182
183
pub fn shrink_to_fit ( & mut self ) {
0 commit comments