Skip to content

Commit

Permalink
perf: don't redundantly add incompatibilities (2x speedup)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Oct 10, 2020
1 parent 21f8841 commit 426fca3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub fn resolve<P: Package, V: Version>(
version: impl Into<V>,
) -> Result<Map<P, V>, PubGrubError<P, V>> {
let mut state = State::init(package.clone(), version.into());
let mut added_dependencies: Map<P, Set<V>> = Map::default();
let mut next = package;
loop {
state.unit_propagation(next)?;
Expand Down Expand Up @@ -145,8 +146,14 @@ pub fn resolve<P: Package, V: Version>(
let start_id = state.incompatibility_store.len();
let dep_incompats =
Incompatibility::from_dependencies(start_id, p.clone(), v.clone(), &dependencies);
for incompat in dep_incompats.iter() {
state.add_incompatibility(|_| incompat.clone());
if added_dependencies
.entry(p.clone())
.or_default()
.insert(v.clone())
{
for incompat in dep_incompats.iter() {
state.add_incompatibility(|_| incompat.clone());
}
}
if dep_incompats
.iter()
Expand Down

0 comments on commit 426fca3

Please sign in to comment.