From 597bf9e9bab8a25e0595c7d10f0cc4269a522b5b Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Thu, 22 Aug 2024 18:14:28 -0400 Subject: [PATCH] perf: remove more redundant scanning (#251) Doing the stronger version of #175 because it turns out to be important to cargo crates. --- src/internal/core.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index 4a8b7bca..0e30d15c 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -128,10 +128,9 @@ impl State { Relation::AlmostSatisfied(package_almost) => { // 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) { + // but so does allocating a hash map and hashing each item. + // In practice `unit_propagation_buffer` is small enough that we can just do a linear scan. + if !self.unit_propagation_buffer.contains(&package_almost) { self.unit_propagation_buffer.push(package_almost.clone()); } // Add (not term) to the partial solution with incompat as cause.