about summary refs log tree commit diff
path: root/compiler/rustc_data_structures
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-01 19:54:55 +0000
committerbors <bors@rust-lang.org>2022-10-01 19:54:55 +0000
commit57f097ea25f2c05f424fc9b9dc50dbd6d399845c (patch)
tree54b2bb2968147e1c6c3e422a18622192334d2ba7 /compiler/rustc_data_structures
parent56a35bc906be1250a76fdb9a4b70e9261e10aec5 (diff)
parentfec53fd9db276d34d8d17701aeb3e81576d761fe (diff)
downloadrust-57f097ea25f2c05f424fc9b9dc50dbd6d399845c.tar.gz
rust-57f097ea25f2c05f424fc9b9dc50dbd6d399845c.zip
Auto merge of #102236 - cjgillot:compute_lint_levels_by_def, r=oli-obk
Compute lint levels by definition

Second attempt to https://github.com/rust-lang/rust/pull/101620.

I think that I have removed the perf regression.
Diffstat (limited to 'compiler/rustc_data_structures')
-rw-r--r--compiler/rustc_data_structures/src/sorted_map.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs
index 937cb671573..fe257e10205 100644
--- a/compiler/rustc_data_structures/src/sorted_map.rs
+++ b/compiler/rustc_data_structures/src/sorted_map.rs
@@ -96,6 +96,23 @@ impl<K: Ord, V> SortedMap<K, V> {
         }
     }
 
+    /// Gets a mutable reference to the value in the entry, or insert a new one.
+    #[inline]
+    pub fn get_mut_or_insert_default(&mut self, key: K) -> &mut V
+    where
+        K: Eq,
+        V: Default,
+    {
+        let index = match self.lookup_index_for(&key) {
+            Ok(index) => index,
+            Err(index) => {
+                self.data.insert(index, (key, V::default()));
+                index
+            }
+        };
+        unsafe { &mut self.data.get_unchecked_mut(index).1 }
+    }
+
     #[inline]
     pub fn clear(&mut self) {
         self.data.clear();