Skip to content

Commit 2d79486

Browse files
committed
just walk active query stack once
1 parent 17c8eb8 commit 2d79486

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

src/cycle.rs

+14
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ impl CycleHeads {
119119
.any(|head| head.database_key_index == *value)
120120
}
121121

122+
pub(crate) fn contains_at_iteration(
123+
&self,
124+
database_key_index: DatabaseKeyIndex,
125+
iteration_count: u32,
126+
) -> bool {
127+
self.into_iter().any(|head| {
128+
head.database_key_index == database_key_index && head.iteration_count == iteration_count
129+
})
130+
}
131+
122132
pub(crate) fn remove(&mut self, value: &DatabaseKeyIndex) -> bool {
123133
let Some(cycle_heads) = &mut self.0 else {
124134
return false;
@@ -134,6 +144,10 @@ impl CycleHeads {
134144
true
135145
}
136146

147+
pub(crate) fn len(&self) -> usize {
148+
self.0.as_ref().map(|heads| heads.len()).unwrap_or_default()
149+
}
150+
137151
pub(crate) fn update_iteration_count(
138152
&mut self,
139153
cycle_head_index: DatabaseKeyIndex,

src/function/maybe_changed_after.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,21 @@ where
276276
"{database_key_index:?}: validate_same_iteration(memo = {memo:#?})",
277277
memo = memo.tracing_debug()
278278
);
279-
for cycle_head in &memo.revisions.cycle_heads {
280-
if !db.zalsa_local().with_query_stack(|stack| {
281-
stack.iter().any(|entry| {
282-
entry.database_key_index == cycle_head.database_key_index
283-
&& entry.iteration_count == cycle_head.iteration_count
284-
})
285-
}) {
286-
return false;
287-
}
288-
}
289279

290-
true
280+
let heads = &memo.revisions.cycle_heads;
281+
let num_heads = heads.len();
282+
db.zalsa_local().with_query_stack(|stack| {
283+
let mut found = 0;
284+
for entry in stack.iter() {
285+
if heads.contains_at_iteration(entry.database_key_index, entry.iteration_count) {
286+
found += 1;
287+
if found == num_heads {
288+
return true;
289+
}
290+
}
291+
}
292+
false
293+
})
291294
}
292295

293296
/// VerifyResult::Unchanged if the memo's value and `changed_at` time is up-to-date in the

0 commit comments

Comments
 (0)