check if input has changed before incrementing revision

WIP -- needs test
This commit is contained in:
Niko Matsakis 2018-10-09 15:56:05 -04:00
parent 6a0ed30d73
commit 3ffd166f2c
2 changed files with 13 additions and 3 deletions

View file

@ -124,9 +124,19 @@ where
Q::Value: Default,
{
fn set(&self, db: &DB, key: &Q::Key, value: Q::Value) {
let map = self.map.upgradable_read();
// If this value was previously stored, check if this is an
// *actual change* before we do anything.
if let Some(old_value) = map.get(key) {
if old_value.value == value {
return;
}
}
let key = key.clone();
let mut map_write = self.map.write();
let mut map = RwLockUpgradableReadGuard::upgrade(map);
// Do this *after* we acquire the lock, so that we are not
// racing with somebody else to modify this same cell.
@ -134,7 +144,7 @@ where
// into the same cell while we block on the lock.)
let changed_at = ChangedAt::Revision(db.salsa_runtime().increment_revision());
map_write.insert(key, StampedValue { value, changed_at });
map.insert(key, StampedValue { value, changed_at });
}
}

View file

@ -170,7 +170,7 @@ where
})
}
/// Assign a value to an "input queries". Must be used outside of
/// Assign a value to an "input query". Must be used outside of
/// an active query computation.
pub fn set(&self, key: Q::Key, value: Q::Value)
where