Skip to content

Commit

Permalink
intern the features
Browse files Browse the repository at this point in the history
In a test on rust-lang#4810 (comment)
Before we got to 5000000 ticks in ~65 sec
After we got to 5000000 ticks in ~52 sec
  • Loading branch information
Eh2406 committed Mar 6, 2018
1 parent 1f764c5 commit aa58d27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/cargo/core/interning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl InternedString {
id_from_str.insert(str.to_string(), str_from_id.len() - 1);
return InternedString { id: str_from_id.len() - 1 }
}
// pub fn to_inner(&self) -> String {
// STRING_CASHE.read().unwrap().0[self.id].to_string()
// }
pub fn to_inner(&self) -> String {
STRING_CASHE.read().unwrap().0[self.id].to_string()
}
}

impl fmt::Debug for InternedString {
Expand Down
12 changes: 5 additions & 7 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ struct Context {
// switch to persistent hash maps if we can at some point or otherwise
// make these much cheaper to clone in general.
activations: Activations,
resolve_features: HashMap<PackageId, HashSet<String>>,
resolve_features: HashMap<PackageId, HashSet<InternedString>>,
links: HashMap<String, PackageId>,

// These are two cheaply-cloneable lists (O(1) clone) which are effectively
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn resolve(summaries: &[(Summary, Method)],
metadata: BTreeMap::new(),
replacements: cx.resolve_replacements(),
features: cx.resolve_features.iter().map(|(k, v)| {
(k.clone(), v.clone())
(k.clone(), v.iter().map(|x| x.to_inner()).collect())
}).collect(),
unused_patches: Vec::new(),
};
Expand Down Expand Up @@ -1318,8 +1318,8 @@ impl Context {
let has_default_feature = summary.features().contains_key("default");
Ok(match self.resolve_features.get(id) {
Some(prev) => {
features.iter().all(|f| prev.contains(f)) &&
(!use_default || prev.contains("default") ||
features.iter().all(|f| prev.contains(&InternedString::new(f))) &&
(!use_default || prev.contains(&InternedString::new("default")) ||
!has_default_feature)
}
None => features.is_empty() && (!use_default || !has_default_feature)
Expand Down Expand Up @@ -1434,9 +1434,7 @@ impl Context {
let set = self.resolve_features.entry(pkgid.clone())
.or_insert_with(HashSet::new);
for feature in reqs.used {
if !set.contains(feature) {
set.insert(feature.to_string());
}
set.insert(InternedString::new(feature));
}
}

Expand Down

0 comments on commit aa58d27

Please sign in to comment.