mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-09 05:38:15 +00:00
refactor to unwrap less
This commit is contained in:
parent
6658a47a36
commit
0dd96865c7
1 changed files with 8 additions and 6 deletions
|
@ -223,13 +223,12 @@ where
|
||||||
// first things first, let's walk over each of our previous
|
// first things first, let's walk over each of our previous
|
||||||
// inputs and check whether they are out of date.
|
// inputs and check whether they are out of date.
|
||||||
if let Some(QueryState::Memoized(old_memo)) = &mut old_value {
|
if let Some(QueryState::Memoized(old_memo)) = &mut old_value {
|
||||||
if old_memo.verify_memoized_value(db) {
|
if let Some(value) = old_memo.verify_memoized_value(db) {
|
||||||
debug!("{:?}({:?}): inputs still valid", Q::default(), key);
|
debug!("{:?}({:?}): inputs still valid", Q::default(), key);
|
||||||
// If none of out inputs have changed since the last time we refreshed
|
// If none of out inputs have changed since the last time we refreshed
|
||||||
// our value, then our value must still be good. We'll just patch
|
// our value, then our value must still be good. We'll just patch
|
||||||
// the verified-at date and re-use it.
|
// the verified-at date and re-use it.
|
||||||
old_memo.verified_at = revision_now;
|
old_memo.verified_at = revision_now;
|
||||||
let value = old_memo.value.clone().unwrap();
|
|
||||||
let changed_at = old_memo.changed_at;
|
let changed_at = old_memo.changed_at;
|
||||||
|
|
||||||
let mut map_write = self.map.write();
|
let mut map_write = self.map.write();
|
||||||
|
@ -430,13 +429,16 @@ where
|
||||||
Q: QueryFunction<DB>,
|
Q: QueryFunction<DB>,
|
||||||
DB: Database,
|
DB: Database,
|
||||||
{
|
{
|
||||||
fn verify_memoized_value(&self, db: &DB) -> bool {
|
fn verify_memoized_value(&self, db: &DB) -> Option<Q::Value> {
|
||||||
// If we don't have a memoized value, nothing to validate.
|
// If we don't have a memoized value, nothing to validate.
|
||||||
if !self.value.is_some() {
|
if let Some(v) = &self.value {
|
||||||
return false;
|
// If inputs are still valid.
|
||||||
|
if self.verify_inputs(db) {
|
||||||
|
return Some(v.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.verify_inputs(db)
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_inputs(&self, db: &DB) -> bool {
|
fn verify_inputs(&self, db: &DB) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue