Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use more Rc in the part of resolver that gets cloned a lot 2 #5302

Merged
merged 2 commits into from
Apr 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/cargo/core/resolver/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Context {
// switch to persistent hash maps if we can at some point or otherwise
// make these much cheaper to clone in general.
pub activations: Activations,
pub resolve_features: HashMap<PackageId, HashSet<InternedString>>,
pub resolve_features: HashMap<PackageId, Rc<HashSet<InternedString>>>,
pub links: HashMap<InternedString, PackageId>,

// These are two cheaply-cloneable lists (O(1) clone) which are effectively
Expand All @@ -36,6 +36,8 @@ pub struct Context {
pub warnings: RcList<String>,
}

pub type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;

impl Context {
pub fn new() -> Context {
Context {
Expand Down Expand Up @@ -66,9 +68,7 @@ impl Context {
&*link
);
}
let mut inner: Vec<_> = (**prev).clone();
inner.push(summary.clone());
*prev = Rc::new(inner);
Rc::make_mut(prev).push(summary.clone());
return Ok(false);
}
debug!("checking if {} is already activated", summary.package_id());
Expand Down Expand Up @@ -244,9 +244,10 @@ impl Context {
if !reqs.used.is_empty() {
let pkgid = s.package_id();

let set = self.resolve_features
let set = Rc::make_mut(self.resolve_features
.entry(pkgid.clone())
.or_insert_with(HashSet::new);
.or_insert_with(|| Rc::new(HashSet::new())));

for feature in reqs.used {
set.insert(InternedString::new(feature));
}
Expand Down Expand Up @@ -405,5 +406,3 @@ impl<'r> Requirements<'r> {
}
}
}

pub type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;