Skip to content

Commit 736c3d7

Browse files
committed
use more Rc in the part of resolver that gets cloned a lot
1 parent 75ec2d3 commit 736c3d7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/cargo/core/resolver/context.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Context {
2323
// switch to persistent hash maps if we can at some point or otherwise
2424
// make these much cheaper to clone in general.
2525
pub activations: Activations,
26-
pub resolve_features: HashMap<PackageId, HashSet<InternedString>>,
26+
pub resolve_features: HashMap<PackageId, Rc<HashSet<InternedString>>>,
2727
pub links: HashMap<InternedString, PackageId>,
2828

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

39+
pub type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;
40+
3941
impl Context {
4042
pub fn new() -> Context {
4143
Context {
@@ -246,10 +248,13 @@ impl Context {
246248

247249
let set = self.resolve_features
248250
.entry(pkgid.clone())
249-
.or_insert_with(HashSet::new);
251+
.or_insert_with(|| Rc::new(HashSet::new()));
252+
253+
let mut inner: HashSet<_> = (**set).clone();
250254
for feature in reqs.used {
251-
set.insert(InternedString::new(feature));
255+
inner.insert(InternedString::new(feature));
252256
}
257+
*set = Rc::new(inner);
253258
}
254259

255260
Ok(ret)
@@ -405,5 +410,3 @@ impl<'r> Requirements<'r> {
405410
}
406411
}
407412
}
408-
409-
pub type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;

0 commit comments

Comments
 (0)