Skip to content

Commit

Permalink
perf: remove redundant scanning (#175)
Browse files Browse the repository at this point in the history
* make a test case

* do not add things to the buffer more than once

* remove useless test

* a cheaper check

* add a comment
  • Loading branch information
Eh2406 authored Mar 11, 2024
1 parent a23e746 commit fdd9cc9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
break;
}
Relation::AlmostSatisfied(package_almost) => {
self.unit_propagation_buffer.push(package_almost.clone());
// Add `package_almost` to the `unit_propagation_buffer` set.
// Putting items in `unit_propagation_buffer` more than once waste cycles,
// but so does checking for duplicates.
// In practice the most common pathology is adding the same package repeatedly.
// So we only check if it is duplicated with the last item.
if self.unit_propagation_buffer.last() != Some(&package_almost) {
self.unit_propagation_buffer.push(package_almost.clone());
}
// Add (not term) to the partial solution with incompat as cause.
self.partial_solution.add_derivation(
package_almost,
Expand Down

0 comments on commit fdd9cc9

Please sign in to comment.