Skip to content

Commit

Permalink
remove collectibles from outdated collectibles
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Sep 19, 2024
1 parent 17acb93 commit f417ecf
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion turbopack/crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ impl MaybeCollectibles {
.or_default();
*value -= count as i32;
}

/// Removes an collectible if the count is positive.
fn remove_emit(&mut self, trait_type: TraitTypeId, value: RawVc) -> bool {
let Some(inner) = self.inner.as_mut() else {
return false;
};

let auto_hash_map::map::Entry::Occupied(mut e) = inner.entry((trait_type, value)) else {
return false;
};
let value = e.get_mut();
*value -= 1;
if *value == 0 {
e.remove();
}
true
}
}

struct InProgressState {
Expand Down Expand Up @@ -1678,9 +1695,18 @@ impl Task {
backend: &MemoryBackend,
turbo_tasks: &dyn TurboTasksBackendApi<MemoryBackend>,
) {
let mut aggregation_context = TaskAggregationContext::new(turbo_tasks, backend);
let mut state = self.full_state_mut();
state.collectibles.emit(trait_type, collectible);
if let TaskStateType::InProgress(box InProgressState {
outdated_collectibles,
..
}) = &mut state.state_type
{
if outdated_collectibles.remove_emit(trait_type, collectible) {
return;
}
}
let mut aggregation_context = TaskAggregationContext::new(turbo_tasks, backend);
let change_job = state.aggregation_node.apply_change(
&aggregation_context,
TaskChange {
Expand Down

0 comments on commit f417ecf

Please sign in to comment.