Skip to content

Commit fdd9cc9

Browse files
authored
perf: remove redundant scanning (pubgrub-rs#175)
* make a test case * do not add things to the buffer more than once * remove useless test * a cheaper check * add a comment
1 parent a23e746 commit fdd9cc9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/internal/core.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> State<P, VS, Priority> {
131131
break;
132132
}
133133
Relation::AlmostSatisfied(package_almost) => {
134-
self.unit_propagation_buffer.push(package_almost.clone());
134+
// Add `package_almost` to the `unit_propagation_buffer` set.
135+
// Putting items in `unit_propagation_buffer` more than once waste cycles,
136+
// but so does checking for duplicates.
137+
// In practice the most common pathology is adding the same package repeatedly.
138+
// So we only check if it is duplicated with the last item.
139+
if self.unit_propagation_buffer.last() != Some(&package_almost) {
140+
self.unit_propagation_buffer.push(package_almost.clone());
141+
}
135142
// Add (not term) to the partial solution with incompat as cause.
136143
self.partial_solution.add_derivation(
137144
package_almost,

0 commit comments

Comments
 (0)