mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 08:30:51 +00:00
Deduplicate QueryStack prefix trimming
This commit is contained in:
parent
f4ea167614
commit
f65ac4b4c3
1 changed files with 24 additions and 21 deletions
|
@ -104,22 +104,13 @@ impl DependencyGraph {
|
||||||
// load up the next thread (i.e., we start at B/QB2,
|
// load up the next thread (i.e., we start at B/QB2,
|
||||||
// and then load up the dependency on C/QC2).
|
// and then load up the dependency on C/QC2).
|
||||||
let edge = self.edges.get_mut(&id).unwrap();
|
let edge = self.edges.get_mut(&id).unwrap();
|
||||||
let prefix = edge
|
closure(strip_prefix_query_stack_mut(&mut edge.stack, key));
|
||||||
.stack
|
|
||||||
.iter_mut()
|
|
||||||
.take_while(|p| p.database_key_index != key)
|
|
||||||
.count();
|
|
||||||
closure(&mut edge.stack[prefix..]);
|
|
||||||
id = edge.blocked_on_id;
|
id = edge.blocked_on_id;
|
||||||
key = edge.blocked_on_key;
|
key = edge.blocked_on_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, we copy in the results from `from_stack`.
|
// Finally, we copy in the results from `from_stack`.
|
||||||
let prefix = from_stack
|
closure(strip_prefix_query_stack_mut(from_stack, key));
|
||||||
.iter_mut()
|
|
||||||
.take_while(|p| p.database_key_index != key)
|
|
||||||
.count();
|
|
||||||
closure(&mut from_stack[prefix..]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unblock each blocked runtime (excluding the current one) if some
|
/// Unblock each blocked runtime (excluding the current one) if some
|
||||||
|
@ -142,15 +133,10 @@ impl DependencyGraph {
|
||||||
let mut others_unblocked = false;
|
let mut others_unblocked = false;
|
||||||
while id != from_id {
|
while id != from_id {
|
||||||
let edge = self.edges.get(&id).unwrap();
|
let edge = self.edges.get(&id).unwrap();
|
||||||
let prefix = edge
|
|
||||||
.stack
|
|
||||||
.iter()
|
|
||||||
.take_while(|p| p.database_key_index != key)
|
|
||||||
.count();
|
|
||||||
let next_id = edge.blocked_on_id;
|
let next_id = edge.blocked_on_id;
|
||||||
let next_key = edge.blocked_on_key;
|
let next_key = edge.blocked_on_key;
|
||||||
|
|
||||||
if let Some(cycle) = edge.stack[prefix..]
|
if let Some(cycle) = strip_prefix_query_stack(&edge.stack, key)
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.find_map(|aq| aq.cycle.clone())
|
.find_map(|aq| aq.cycle.clone())
|
||||||
|
@ -171,11 +157,9 @@ impl DependencyGraph {
|
||||||
key = next_key;
|
key = next_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix = from_stack
|
let this_unblocked = strip_prefix_query_stack(from_stack, key)
|
||||||
.iter()
|
.iter()
|
||||||
.take_while(|p| p.database_key_index != key)
|
.any(|aq| aq.cycle.is_some());
|
||||||
.count();
|
|
||||||
let this_unblocked = from_stack[prefix..].iter().any(|aq| aq.cycle.is_some());
|
|
||||||
|
|
||||||
(this_unblocked, others_unblocked)
|
(this_unblocked, others_unblocked)
|
||||||
}
|
}
|
||||||
|
@ -276,3 +260,22 @@ impl DependencyGraph {
|
||||||
edge.condvar.notify_one();
|
edge.condvar.notify_one();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn strip_prefix_query_stack(stack_mut: &[ActiveQuery], key: DatabaseKeyIndex) -> &[ActiveQuery] {
|
||||||
|
let prefix = stack_mut
|
||||||
|
.iter()
|
||||||
|
.take_while(|p| p.database_key_index != key)
|
||||||
|
.count();
|
||||||
|
&stack_mut[prefix..]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn strip_prefix_query_stack_mut(
|
||||||
|
stack_mut: &mut [ActiveQuery],
|
||||||
|
key: DatabaseKeyIndex,
|
||||||
|
) -> &mut [ActiveQuery] {
|
||||||
|
let prefix = stack_mut
|
||||||
|
.iter()
|
||||||
|
.take_while(|p| p.database_key_index != key)
|
||||||
|
.count();
|
||||||
|
&mut stack_mut[prefix..]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue