Fix marking nodes as dirty when inserting into an existing hashmap entry (#4959)
* Fix marking nodes as dirty when inserting into an existing hashmap entry * remove logs
This commit is contained in:
1 parent
317abedece
commit
bd2d1de873
3 files changed
+24
-1
No files matched your search
@@ -131,7 +131,15 @@ impl<Lens: Readable<Target = BTreeMap<K, V>> + 'static, K: 'static, V: 'static>
|
|||||||
K: Ord,
|
K: Ord,
|
||||||
Lens: Writable,
|
Lens: Writable,
|
||||||
{
|
{
|
||||||
self.selector().mark_dirty_shallow();
|
// TODO: This method was released in 0.7 without the hash bound so we don't have a way
|
||||||
|
// to mark only the existing value as dirty. Instead we need to check if the value already exists
|
||||||
|
// in the map and mark the whole map as dirty if it does.
|
||||||
|
// In the 0.8 release, we should change this method to only mark the existing value as dirty.
|
||||||
|
if self.peek().contains_key(&key) {
|
||||||
|
self.selector().mark_dirty();
|
||||||
|
} else {
|
||||||
|
self.selector().mark_dirty_shallow();
|
||||||
|
}
|
||||||
self.selector().write_untracked().insert(key, value);
|
self.selector().write_untracked().insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,13 @@ impl<Lens: Readable<Target = HashMap<K, V, St>> + 'static, K: 'static, V: 'stati
|
|||||||
St: BuildHasher,
|
St: BuildHasher,
|
||||||
Lens: Writable,
|
Lens: Writable,
|
||||||
{
|
{
|
||||||
|
// Mark the store itself as dirty since the keys may have changed
|
||||||
self.selector().mark_dirty_shallow();
|
self.selector().mark_dirty_shallow();
|
||||||
|
// Mark the existing value as dirty if it exists
|
||||||
|
self.selector()
|
||||||
|
.as_ref()
|
||||||
|
.hash_child_unmapped(key.borrow())
|
||||||
|
.mark_dirty();
|
||||||
self.selector().write_untracked().insert(key, value);
|
self.selector().write_untracked().insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,15 @@ impl<Lens> SelectorScope<Lens> {
|
|||||||
{
|
{
|
||||||
self.write.write_unchecked()
|
self.write.write_unchecked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Borrow the writer
|
||||||
|
pub(crate) fn as_ref(&self) -> SelectorScope<&Lens> {
|
||||||
|
SelectorScope {
|
||||||
|
path: self.path,
|
||||||
|
store: self.store,
|
||||||
|
write: &self.write,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Lens: Readable> Readable for SelectorScope<Lens> {
|
impl<Lens: Readable> Readable for SelectorScope<Lens> {
|
||||||
|
|||||||
Reference in new issue
Block a user