Skip to content

Commit 26b9372

Browse files
committed
Simplify calls to find_existing_entry
1 parent 4f47f49 commit 26b9372

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/map.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,9 @@ impl<K, V, S> IndexMap<K, V, S> {
620620
///
621621
/// Computes in **O(1)** time (average).
622622
pub fn swap_remove_index(&mut self, index: usize) -> Option<(K, V)> {
623-
let (probe, found) = match self
624-
.as_entries()
625-
.get(index)
626-
.map(|e| self.core.find_existing_entry(e))
627-
{
623+
let (probe, found) = match self.as_entries().get(index) {
624+
Some(e) => self.core.find_existing_entry(e),
628625
None => return None,
629-
Some(t) => t,
630626
};
631627
Some(self.core.swap_remove_found(probe, found))
632628
}
@@ -641,13 +637,9 @@ impl<K, V, S> IndexMap<K, V, S> {
641637
///
642638
/// Computes in **O(n)** time (average).
643639
pub fn shift_remove_index(&mut self, index: usize) -> Option<(K, V)> {
644-
let (probe, found) = match self
645-
.as_entries()
646-
.get(index)
647-
.map(|e| self.core.find_existing_entry(e))
648-
{
640+
let (probe, found) = match self.as_entries().get(index) {
641+
Some(e) => self.core.find_existing_entry(e),
649642
None => return None,
650-
Some(t) => t,
651643
};
652644
Some(self.core.shift_remove_found(probe, found))
653645
}

src/map_core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ impl<K, V> IndexMapCore<K, V> {
566566
}
567567

568568
pub(crate) fn pop_impl(&mut self) -> Option<(K, V)> {
569-
let (probe, found) = match self.entries.last().map(|e| self.find_existing_entry(e)) {
569+
let (probe, found) = match self.as_entries().last() {
570+
Some(e) => self.find_existing_entry(e),
570571
None => return None,
571-
Some(t) => t,
572572
};
573573
debug_assert_eq!(found, self.entries.len() - 1);
574574
Some(self.swap_remove_found(probe, found))

0 commit comments

Comments
 (0)