about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorpawanbisht62 <36775517+pawanbisht62@users.noreply.github.com>2020-08-10 13:19:24 +0530
committerGitHub <noreply@github.com>2020-08-10 13:19:24 +0530
commit7c4ef37e19c0f9f501c04dd7bb1d5b864f0b6a2b (patch)
treedb7bfedf0de60ca646cce61f54d70100dccb623c /src/librustc_data_structures
parentbac939edcf2137f625cfd7b56dfa4aa7b814868f (diff)
parent568f6195bbf3c04a601a297a386e0e1dc0ca8333 (diff)
downloadrust-7c4ef37e19c0f9f501c04dd7bb1d5b864f0b6a2b.tar.gz
rust-7c4ef37e19c0f9f501c04dd7bb1d5b864f0b6a2b.zip
Merge branch 'master' into feature/incorporate-tracing
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/Cargo.toml2
-rw-r--r--src/librustc_data_structures/transitive_relation.rs39
2 files changed, 14 insertions, 27 deletions
diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml
index 386096b416f..fda0fc5973b 100644
--- a/src/librustc_data_structures/Cargo.toml
+++ b/src/librustc_data_structures/Cargo.toml
@@ -11,7 +11,7 @@ doctest = false
 
 [dependencies]
 ena = "0.14"
-indexmap = "1"
+indexmap = "1.5.1"
 tracing = "0.1"
 jobserver_crate = { version = "0.1.13", package = "jobserver" }
 lazy_static = "1"
diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs
index 189da3395ad..7d137a55033 100644
--- a/src/librustc_data_structures/transitive_relation.rs
+++ b/src/librustc_data_structures/transitive_relation.rs
@@ -1,4 +1,4 @@
-use crate::fx::FxHashMap;
+use crate::fx::FxIndexSet;
 use crate::stable_hasher::{HashStable, StableHasher};
 use crate::sync::Lock;
 use rustc_index::bit_set::BitMatrix;
@@ -13,10 +13,7 @@ mod tests;
 #[derive(Clone, Debug)]
 pub struct TransitiveRelation<T: Eq + Hash> {
     // List of elements. This is used to map from a T to a usize.
-    elements: Vec<T>,
-
-    // Maps each element to an index.
-    map: FxHashMap<T, Index>,
+    elements: FxIndexSet<T>,
 
     // List of base edges in the graph. Require to compute transitive
     // closure.
@@ -39,7 +36,6 @@ impl<T: Eq + Hash> Default for TransitiveRelation<T> {
     fn default() -> Self {
         TransitiveRelation {
             elements: Default::default(),
-            map: Default::default(),
             edges: Default::default(),
             closure: Default::default(),
         }
@@ -65,20 +61,16 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
     }
 
     fn index(&self, a: &T) -> Option<Index> {
-        self.map.get(a).cloned()
+        self.elements.get_index_of(a).map(Index)
     }
 
     fn add_index(&mut self, a: T) -> Index {
-        let &mut TransitiveRelation { ref mut elements, ref mut closure, ref mut map, .. } = self;
-
-        *map.entry(a.clone()).or_insert_with(|| {
-            elements.push(a);
-
+        let (index, added) = self.elements.insert_full(a);
+        if added {
             // if we changed the dimensions, clear the cache
-            *closure.get_mut() = None;
-
-            Index(elements.len() - 1)
-        })
+            *self.closure.get_mut() = None;
+        }
+        Index(index)
     }
 
     /// Applies the (partial) function to each edge and returns a new
@@ -430,14 +422,11 @@ where
 {
     fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
         d.read_struct("TransitiveRelation", 2, |d| {
-            let elements: Vec<T> = d.read_struct_field("elements", 0, |d| Decodable::decode(d))?;
-            let edges = d.read_struct_field("edges", 1, |d| Decodable::decode(d))?;
-            let map = elements
-                .iter()
-                .enumerate()
-                .map(|(index, elem)| (elem.clone(), Index(index)))
-                .collect();
-            Ok(TransitiveRelation { elements, edges, map, closure: Lock::new(None) })
+            Ok(TransitiveRelation {
+                elements: d.read_struct_field("elements", 0, |d| Decodable::decode(d))?,
+                edges: d.read_struct_field("edges", 1, |d| Decodable::decode(d))?,
+                closure: Lock::new(None),
+            })
         })
     }
 }
@@ -452,8 +441,6 @@ where
         let TransitiveRelation {
             ref elements,
             ref edges,
-            // "map" is just a copy of elements vec
-            map: _,
             // "closure" is just a copy of the data above
             closure: _,
         } = *self;