about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-08-01 06:55:55 +0200
committerGitHub <noreply@github.com>2023-08-01 06:55:55 +0200
commita902550233f2b6c3e039a3beab814ec3527f2c9e (patch)
tree30f987a5d5738cc041c1be7f336e65025f3ab6f9 /compiler
parentff8b96f88b1d1999e04658c60cccc56075ddc998 (diff)
parent9eae73a5de31e94db9f85f75f6b08934946f5bcc (diff)
downloadrust-a902550233f2b6c3e039a3beab814ec3527f2c9e.tar.gz
rust-a902550233f2b6c3e039a3beab814ec3527f2c9e.zip
Rollup merge of #114313 - ttsugriy:sm-insert, r=petrochenkov
[rustc_data_structures] Simplify SortedMap::insert.

It looks like current usage of `swap` is aimed at achieving what `std::mem::replace` does but more concisely and idiomatically.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_data_structures/src/sorted_map.rs5
1 files changed, 2 insertions, 3 deletions
diff --git a/compiler/rustc_data_structures/src/sorted_map.rs b/compiler/rustc_data_structures/src/sorted_map.rs
index 9409057d484..60b343afbed 100644
--- a/compiler/rustc_data_structures/src/sorted_map.rs
+++ b/compiler/rustc_data_structures/src/sorted_map.rs
@@ -49,12 +49,11 @@ impl<K: Ord, V> SortedMap<K, V> {
     }
 
     #[inline]
-    pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
+    pub fn insert(&mut self, key: K, value: V) -> Option<V> {
         match self.lookup_index_for(&key) {
             Ok(index) => {
                 let slot = unsafe { self.data.get_unchecked_mut(index) };
-                mem::swap(&mut slot.1, &mut value);
-                Some(value)
+                Some(mem::replace(&mut slot.1, value))
             }
             Err(index) => {
                 self.data.insert(index, (key, value));