mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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.
This commit is contained in:
commit
a902550233
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user