Skip to content

Commit 597bf9e

Browse files
authored
perf: remove more redundant scanning (#251)
Doing the stronger version of #175 because it turns out to be important to cargo crates.
1 parent eb528c3 commit 597bf9e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/internal/core.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ impl<DP: DependencyProvider> State<DP> {
128128
Relation::AlmostSatisfied(package_almost) => {
129129
// Add `package_almost` to the `unit_propagation_buffer` set.
130130
// Putting items in `unit_propagation_buffer` more than once waste cycles,
131-
// but so does checking for duplicates.
132-
// In practice the most common pathology is adding the same package repeatedly.
133-
// So we only check if it is duplicated with the last item.
134-
if self.unit_propagation_buffer.last() != Some(&package_almost) {
131+
// but so does allocating a hash map and hashing each item.
132+
// In practice `unit_propagation_buffer` is small enough that we can just do a linear scan.
133+
if !self.unit_propagation_buffer.contains(&package_almost) {
135134
self.unit_propagation_buffer.push(package_almost.clone());
136135
}
137136
// Add (not term) to the partial solution with incompat as cause.

0 commit comments

Comments
 (0)