message: extract a `set_common` helper
diff: @@ -70,6 +70,30 @@ where
  changed_at: ChangedAt::Revision(Revision::ZERO),
  })
  }
  +
  + fn set_common(&self, key: &Q::Key, value: Q::Value, changed_at: impl FnOnce() -> ChangedAt) {
  + 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 = RwLockUpgradableReadGuard::upgrade(map);
  +
  + // Do this *after* we acquire the lock, so that we are not
  + // racing with somebody else to modify this same cell.
  + // (Otherwise, someone else might write a *newer* revision
  + // into the same cell while we block on the lock.)
  + let changed_at = changed_at();
  +
  + map.insert(key, StampedValue { value, changed_at });
  + }
  }
  impl<DB, Q> QueryStorageOps<DB, Q> for InputStorage<DB, Q>
  @@ -124,27 +148,9 @@ 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 = RwLockUpgradableReadGuard::upgrade(map);
  -
  - // Do this *after* we acquire the lock, so that we are not
  - // racing with somebody else to modify this same cell.
  - // (Otherwise, someone else might write a *newer* revision
  - // into the same cell while we block on the lock.)
  - let changed_at = ChangedAt::Revision(db.salsa_runtime().increment_revision());
  -
  - map.insert(key, StampedValue { value, changed_at });
  + self.set_common(key, value, || {
  + ChangedAt::Revision(db.salsa_runtime().increment_revision())
  + });
  }
  }
  