Skip to content

Commit

Permalink
Use a SmallBitVec in detect_cycles.
Browse files Browse the repository at this point in the history
  • Loading branch information
linabutler committed Feb 23, 2019
1 parent 4a4b53a commit 27ecc8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ authors = ["Lina Cambridge <lina@mozilla.com>"]
license = "Apache-2.0"
exclude = [".travis", ".travis.yml"]
edition = "2018"

[dependencies]
smallbitvec = "2.3.0"
6 changes: 4 additions & 2 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::{cmp::Ordering,
ops::Deref,
ptr};

use smallbitvec::SmallBitVec;

use crate::error::{ErrorKind, Result};
use crate::guid::{Guid, ROOT_GUID};

Expand Down Expand Up @@ -760,7 +762,7 @@ impl ResolvedParent {
/// algorithm. Returns the index of the entry where the cycle was detected,
/// or `None` if there aren't any cycles.
fn detect_cycles(parents: &[ResolvedParent]) -> Option<Index> {
let mut seen = vec![false; parents.len()];
let mut seen = SmallBitVec::from_elem(parents.len(), false);
for (entry_index, parent) in parents.iter().enumerate() {
if seen[entry_index] {
continue;
Expand All @@ -780,7 +782,7 @@ fn detect_cycles(parents: &[ResolvedParent]) -> Option<Index> {
.and_then(|index| parents[index].index())
.and_then(|index| parents[index].index());
}
seen[entry_index] = true;
seen.set(entry_index, true);
}
None
}
Expand Down

0 comments on commit 27ecc8d

Please sign in to comment.