use more Rc in the part of resolver that gets cloned a lot
authorEh2406 <YeomanYaacov@gmail.com>
Thu, 5 Apr 2018 20:34:49 +0000 (16:34 -0400)
committerEh2406 <YeomanYaacov@gmail.com>
Thu, 5 Apr 2018 20:34:49 +0000 (16:34 -0400)
src/cargo/core/resolver/context.rs

index b2b49a6b5a2c76a37c918ba6aab30fb6ae09ad03..f132463e3c8ba77eddecf50fdc724956e6262d22 100644 (file)
@@ -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
@@ -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 {
@@ -246,10 +248,13 @@ impl Context {
 
             let set = self.resolve_features
                 .entry(pkgid.clone())
-                .or_insert_with(HashSet::new);
+                .or_insert_with(|| Rc::new(HashSet::new()));
+
+            let mut inner: HashSet<_> = (**set).clone();
             for feature in reqs.used {
-                set.insert(InternedString::new(feature));
+                inner.insert(InternedString::new(feature));
             }
+            *set = Rc::new(inner);
         }
 
         Ok(ret)
@@ -405,5 +410,3 @@ impl<'r> Requirements<'r> {
         }
     }
 }
-
-pub type Activations = HashMap<(InternedString, SourceId), Rc<Vec<Summary>>>;