@@ -215,6 +215,14 @@ impl<T> DictInner<T> {
215
215
None
216
216
}
217
217
}
218
+
219
+ #[ inline]
220
+ fn get_entry_checked ( & self , idx : EntryIndex , index_index : IndexIndex ) -> Option < & DictEntry < T > > {
221
+ match self . entries . get ( idx) {
222
+ Some ( Some ( entry) ) if entry. index == index_index => Some ( entry) ,
223
+ _ => None ,
224
+ }
225
+ }
218
226
}
219
227
220
228
type PopInnerResult < T > = ControlFlow < Option < DictEntry < T > > > ;
@@ -284,13 +292,8 @@ impl<T: Clone> Dict<T> {
284
292
let ( entry, index_index) = self . lookup ( vm, key, hash, None ) ?;
285
293
if let Some ( index) = entry. index ( ) {
286
294
let inner = self . read ( ) ;
287
- if let Some ( entry) = inner. entries . get ( index) {
288
- let entry = extract_dict_entry ( entry) ;
289
- if entry. index == index_index {
290
- break Some ( entry. value . clone ( ) ) ;
291
- } else {
292
- // stuff shifted around, let's try again
293
- }
295
+ if let Some ( entry) = inner. get_entry_checked ( index, index_index) {
296
+ break Some ( entry. value . clone ( ) ) ;
294
297
} else {
295
298
// The dict was changed since we did lookup. Let's try again.
296
299
continue ;
@@ -395,13 +398,8 @@ impl<T: Clone> Dict<T> {
395
398
let ( index_entry, index_index) = lookup;
396
399
if let Some ( index) = index_entry. index ( ) {
397
400
let inner = self . read ( ) ;
398
- if let Some ( entry) = inner. entries . get ( index) {
399
- let entry = extract_dict_entry ( entry) ;
400
- if entry. index == index_index {
401
- break entry. value . clone ( ) ;
402
- } else {
403
- // stuff shifted around, let's try again
404
- }
401
+ if let Some ( entry) = inner. get_entry_checked ( index, index_index) {
402
+ break entry. value . clone ( ) ;
405
403
} else {
406
404
// The dict was changed since we did lookup, let's try again.
407
405
continue ;
@@ -439,13 +437,8 @@ impl<T: Clone> Dict<T> {
439
437
let ( index_entry, index_index) = lookup;
440
438
if let Some ( index) = index_entry. index ( ) {
441
439
let inner = self . read ( ) ;
442
- if let Some ( entry) = inner. entries . get ( index) {
443
- let entry = extract_dict_entry ( entry) ;
444
- if entry. index == index_index {
445
- break ( entry. key . clone ( ) , entry. value . clone ( ) ) ;
446
- } else {
447
- // stuff shifted around, let's try again
448
- }
440
+ if let Some ( entry) = inner. get_entry_checked ( index, index_index) {
441
+ break ( entry. key . clone ( ) , entry. value . clone ( ) ) ;
449
442
} else {
450
443
// The dict was changed since we did lookup, let's try again.
451
444
continue ;
@@ -886,12 +879,6 @@ fn str_exact<'a>(obj: &'a PyObject, vm: &VirtualMachine) -> Option<&'a PyStr> {
886
879
}
887
880
}
888
881
889
- fn extract_dict_entry < T > ( option_entry : & Option < DictEntry < T > > ) -> & DictEntry < T > {
890
- option_entry
891
- . as_ref ( )
892
- . expect ( "The dict was changed since we did lookup." )
893
- }
894
-
895
882
#[ cfg( test) ]
896
883
mod tests {
897
884
use super :: { Dict , DictKey } ;
0 commit comments