@@ -871,33 +871,17 @@ where
871
871
// the lifetime of the guard.
872
872
let guard = & * ( guard as * const _ ) ;
873
873
874
- let mut search;
875
- loop {
876
- // First try searching for the key.
877
- // Note that the `Ord` implementation for `K` may panic during the search.
878
- search = self . search_position ( & key, guard) ;
879
-
880
- let r = match search. found {
881
- Some ( r) => r,
882
- None => break ,
883
- } ;
874
+ // First try searching for the key.
875
+ // Note that the `Ord` implementation for `K` may panic during the search.
876
+ let mut search = self . search_position ( & key, guard) ;
877
+ if let Some ( r) = search. found {
884
878
let replace = replace ( & r. value ) ;
885
- if replace {
886
- // If a node with the key was found and we should replace it, mark its tower
887
- // and then repeat the search.
888
- if r. mark_tower ( ) {
889
- self . hot_data . len . fetch_sub ( 1 , Ordering :: Relaxed ) ;
890
- }
891
- } else {
879
+ if !replace {
892
880
// If a node with the key was found and we're not going to replace it, let's
893
881
// try returning it as an entry.
894
882
if let Some ( e) = RefEntry :: try_acquire ( self , r) {
895
883
return e;
896
884
}
897
-
898
- // If we couldn't increment the reference count, that means someone has just
899
- // now removed the node.
900
- break ;
901
885
}
902
886
}
903
887
@@ -937,6 +921,12 @@ where
937
921
)
938
922
. is_ok ( )
939
923
{
924
+ // This node has been abandoned
925
+ if let Some ( r) = search. found {
926
+ if r. mark_tower ( ) {
927
+ self . hot_data . len . fetch_sub ( 1 , Ordering :: Relaxed ) ;
928
+ }
929
+ }
940
930
break ;
941
931
}
942
932
@@ -956,13 +946,7 @@ where
956
946
957
947
if let Some ( r) = search. found {
958
948
let replace = replace ( & r. value ) ;
959
- if replace {
960
- // If a node with the key was found and we should replace it, mark its
961
- // tower and then repeat the search.
962
- if r. mark_tower ( ) {
963
- self . hot_data . len . fetch_sub ( 1 , Ordering :: Relaxed ) ;
964
- }
965
- } else {
949
+ if !replace {
966
950
// If a node with the key was found and we're not going to replace it,
967
951
// let's try returning it as an entry.
968
952
if let Some ( e) = RefEntry :: try_acquire ( self , r) {
0 commit comments