Skip to content

Commit

Permalink
support get_mut not same key
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Apr 26, 2024
1 parent 0892e67 commit b102399
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/sync/map_btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,15 @@ impl<K: Eq + Hash, V> SyncBtreeMap<K, V>
m.insert(k.clone(), g);
}
let g = m.get(k).unwrap();
drop(get_mut_lock);
let m = unsafe { &mut *self.dirty.get() };
Some(BtreeMapRefMut {
let v = BtreeMapRefMut {
k: unsafe { std::mem::transmute(&k) },
m: self,
_g: g.lock(),
value: m.get_mut(k)?,
})
};
drop(get_mut_lock);
Some(v)
}

#[inline]
Expand Down
7 changes: 4 additions & 3 deletions src/sync/map_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,17 @@ impl<K, V> SyncHashMap<K, V>
m.insert(k.clone(), g);
}
let g = m.get(k).unwrap();
drop(get_mut_lock);
Some(HashMapRefMut {
let v = HashMapRefMut {
k: unsafe { std::mem::transmute(&k) },
m: self,
_g: g.lock(),
value: {
let m = unsafe { &mut *self.dirty.get() };
m.get_mut(k)?
},
})
};
drop(get_mut_lock);
Some(v)
}

#[inline]
Expand Down

0 comments on commit b102399

Please sign in to comment.