Skip to content

Commit

Permalink
Merge pull request #60 from thomastaylor312/ref/filter_cleanup
Browse files Browse the repository at this point in the history
ref(filter): Removes some unneeded allocations
  • Loading branch information
thomastaylor312 authored Dec 12, 2020
2 parents 02a24b3 + c21a83c commit d22acbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions src/filters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ pub struct BindleFilter {
impl BindleFilter {
pub fn new(invoice: Invoice) -> Self {
Self {
// For now, we clone just in case we have to mutate the invoice in the builder.
// If it turns out we don't need to mutate the invoice, then we can use a ref
// instead.
invoice,
groups: HashSet::new(),
exclude_groups: HashSet::new(),
Expand Down Expand Up @@ -276,7 +273,7 @@ impl BindleFilter {
.parcel
.clone()
.unwrap_or_else(Vec::new)
.iter()
.into_iter()
.filter(|p| {
// Filter out any parcels that are not part of the global group or one
// of the enabled groups.
Expand All @@ -295,23 +292,22 @@ impl BindleFilter {
.unwrap_or(true) // No conditions means parcel is in global group
})
.filter(|p| !self.is_disabled(p))
.cloned()
.collect();

// Loop through the parcels and see if any of them require in more groups.
// If so, descend down that tree and add parcels.
let mut dependencies: HashSet<Parcel> = HashSet::new();
parcels.iter().for_each(|p| {
let dependencies: HashSet<Parcel> = parcels.iter().fold(HashSet::new(), |mut deps, p| {
if let Some(extras) = self.walk_parcel_requires(p, &mut groups) {
dependencies.extend(extras)
deps.extend(extras)
}
deps
});

// Add all of the dependencies to the main parcel list.
parcels.extend(dependencies);

// There is probably a better way to do this.
parcels.iter().cloned().collect()
// Collect it into a Vec
parcels.into_iter().collect()
}

/// Given a parcel, get a list of all of the parcels that are required via groups.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub struct Label {
}

impl Label {
fn new(name: String, sha256: String) -> Self {
pub fn new(name: String, sha256: String) -> Self {
Label {
name,
sha256,
Expand Down

0 comments on commit d22acbf

Please sign in to comment.