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:
Evan Almloff authored and GitHub committed 2025-11-12 23:13:56 -03:00
1 parent 317abedece
commit bd2d1de873
3 files changed
+23

No files matched your search

+8
View File
@@ -131,7 +131,15 @@ impl<Lens: Readable<Target = BTreeMap<K, V>> + 'static, K: 'static, V: 'static>
K: Ord,
Lens: Writable,
{
// 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);
}
+6
View File
@@ -139,7 +139,13 @@ impl<Lens: Readable<Target = HashMap<K, V, St>> + 'static, K: 'static, V: 'stati
St: BuildHasher,
Lens: Writable,
{
// Mark the store itself as dirty since the keys may have changed
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);
}
+9
View File
@@ -185,6 +185,15 @@ impl<Lens> SelectorScope<Lens> {
{
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> {