Skip to content

Commit

Permalink
try to make it faster
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed Mar 19, 2022
1 parent 07bc8d3 commit d0fa006
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions crates/rattler/src/match_spec_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{MatchSpec, PackageRecord, Range, Version};
use itertools::Itertools;
use once_cell::sync::OnceCell;
use pubgrub::version_set::VersionSet;
use smallvec::SmallVec;
use std::collections::hash_map::DefaultHasher;
use std::collections::{HashMap, HashSet};
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -97,37 +96,39 @@ impl MatchSpecConstraints {
groups: vec![MatchSpecElement::any()],
}
} else {
let mut permutations = Vec::with_capacity(self.groups.len());
let mut groups: HashSet<_> = [MatchSpecElement::any()].into();
let mse_none = MatchSpecElement::none();
for spec in self.groups.iter() {
let mut group_entries: SmallVec<[MatchSpecElement; 2]> = SmallVec::new();
let mut next = HashSet::new();
let version_complement = spec.version.negate();
if version_complement != Range::none() {
group_entries.push(MatchSpecElement {
let version_complement = MatchSpecElement {
version: version_complement,
build_number: Range::any(),
});
};
next.extend(
groups
.iter()
.map(|o| o.intersection(&version_complement))
.filter(|n| n != &mse_none),
);
}

let build_complement = spec.build_number.negate();
if build_complement != Range::none() {
group_entries.push(MatchSpecElement {
let build_complement = MatchSpecElement {
version: Range::any(),
build_number: spec.build_number.negate(),
});
build_number: build_complement,
};
next.extend(
groups
.iter()
.map(|o| o.intersection(&build_complement))
.filter(|n| n != &mse_none),
);
}

permutations.push(group_entries);
}

let mut groups = HashSet::new();
for perm in permutations.into_iter().multi_cartesian_product() {
let group = perm.into_iter().reduce(|a, b| a.intersection(&b)).unwrap();

if group == MatchSpecElement::any() {
return MatchSpecConstraints::from(group);
} else if group != MatchSpecElement::none() {
groups.insert(group);
}
groups = next;
}

Self {
Expand Down Expand Up @@ -180,7 +181,7 @@ impl VersionSet for MatchSpecConstraints {
}
}

dbg!("-- NOT CACHED", self);
// dbg!("-- NOT CACHED", self);

let complement = self.compute_complement();
{
Expand Down Expand Up @@ -217,6 +218,8 @@ impl VersionSet for MatchSpecConstraints {
hasher.finish()
});

groups.dedup();

Self { groups }
}

Expand Down

0 comments on commit d0fa006

Please sign in to comment.