about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2018-05-16 20:59:27 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2018-05-17 09:34:20 +1000
commitf778bdefdd9663aa78c31ffc7773e31bcae4fb39 (patch)
treeffa3ff5d6f360749f1753c0d7e8b56b79432d5fb /src/librustc_data_structures
parent6fc409ed0938cd2f501642abcaa675977fa5035a (diff)
downloadrust-f778bdefdd9663aa78c31ffc7773e31bcae4fb39.tar.gz
rust-f778bdefdd9663aa78c31ffc7773e31bcae4fb39.zip
Avoid repeated HashMap lookups in `opt_normalize_projection_type`.
There is a hot path through `opt_normalize_projection_type`:
- `try_start` does a cache lookup (#1).
- The result is a `NormalizedTy`.
- There are no unresolved type vars, so we call `complete`.
- `complete` does *another* cache lookup (#2), then calls
  `SnapshotMap::insert`.
- `insert` does *another* cache lookup (#3), inserting the same value
  that's already in the cache.

This patch optimizes this hot path by introducing `complete_normalized`,
for use when the value is known in advance to be a `NormalizedTy`. It
always avoids lookup #2. Furthermore, if the `NormalizedTy`'s
obligations are empty (the common case), we know that lookup #3 would be
a no-op, so we avoid it, while inserting a Noop into the `SnapshotMap`'s
undo log.
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/snapshot_map/mod.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs
index cede6f14782..6ee8c3579f5 100644
--- a/src/librustc_data_structures/snapshot_map/mod.rs
+++ b/src/librustc_data_structures/snapshot_map/mod.rs
@@ -67,6 +67,12 @@ impl<K, V> SnapshotMap<K, V>
         }
     }
 
+    pub fn insert_noop(&mut self) {
+        if !self.undo_log.is_empty() {
+            self.undo_log.push(UndoLog::Noop);
+        }
+    }
+
     pub fn remove(&mut self, key: K) -> bool {
         match self.map.remove(&key) {
             Some(old_value) => {