Skip to content

Commit 12bcddc

Browse files
committed
Also drop+return value if replaced
1 parent 1f49970 commit 12bcddc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/map.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,15 +1176,16 @@ where
11761176

11771177
// just remove the node if the value is the one we expected at method call
11781178
if observed_value.map(|ov| ov == ev).unwrap_or(true) {
1179+
// we remember the old value so that we can return it and mark it for deletion below
1180+
old_val = Some(ev);
1181+
11791182
// found the node but we have a new value to replace the old one
11801183
if let Some(nv) = new_value {
11811184
n.value.store(Owned::new(nv), Ordering::SeqCst);
11821185
// we are just replacing entry value and we do not want to remove the node
11831186
// so we stop iterating here
11841187
break;
11851188
}
1186-
// we remember the old value so that we can return it and mark it for deletion below
1187-
old_val = Some(ev);
11881189
// remove the BinEntry containing the removed key value pair from the bucket
11891190
if !pred.is_null() {
11901191
// either by changing the pointer of the previous BinEntry, if present
@@ -1701,7 +1702,7 @@ fn replace_existing() {
17011702
let guard = epoch::pin();
17021703
map.insert(42, 42, &guard);
17031704
let old = map.replace_node(&42, Some(10), None, &guard);
1704-
assert!(old.is_none());
1705+
assert_eq!(old, Some(&42));
17051706
assert_eq!(*map.get(&42, &guard).unwrap(), 10);
17061707
}
17071708
}
@@ -1714,7 +1715,7 @@ fn replace_existing_observed_value_matching() {
17141715
map.insert(42, 42, &guard);
17151716
let observed_value = Shared::from(map.get(&42, &guard).unwrap() as *const _);
17161717
let old = map.replace_node(&42, Some(10), Some(observed_value), &guard);
1717-
assert!(old.is_none());
1718+
assert_eq!(old, Some(&42));
17181719
assert_eq!(*map.get(&42, &guard).unwrap(), 10);
17191720
}
17201721
}

0 commit comments

Comments
 (0)