Skip to content

Commit a902550

Browse files
authored
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.
2 parents ff8b96f + 9eae73a commit a902550

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

compiler/rustc_data_structures/src/sorted_map.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ impl<K: Ord, V> SortedMap<K, V> {
4949
}
5050

5151
#[inline]
52-
pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
52+
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
5353
match self.lookup_index_for(&key) {
5454
Ok(index) => {
5555
let slot = unsafe { self.data.get_unchecked_mut(index) };
56-
mem::swap(&mut slot.1, &mut value);
57-
Some(value)
56+
Some(mem::replace(&mut slot.1, value))
5857
}
5958
Err(index) => {
6059
self.data.insert(index, (key, value));

0 commit comments

Comments
 (0)