Skip to content

Commit 185ed98

Browse files
committed
Remove the Recover trait for HashSet
1 parent 0550766 commit 185ed98

File tree

3 files changed

+9
-52
lines changed

3 files changed

+9
-52
lines changed

src/libstd/collections/hash/map.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,13 +2937,6 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
29372937
pop_internal(self.elem).1
29382938
}
29392939

2940-
/// Returns a key that was used for search.
2941-
///
2942-
/// The key was retained for further use.
2943-
fn take_key(&mut self) -> Option<K> {
2944-
self.key.take()
2945-
}
2946-
29472940
/// Replaces the entry, returning the old key and value. The new key in the hash map will be
29482941
/// the key used to create this entry.
29492942
///
@@ -3262,39 +3255,6 @@ impl fmt::Debug for RandomState {
32623255
}
32633256
}
32643257

3265-
impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S>
3266-
where K: Eq + Hash + Borrow<Q>,
3267-
S: BuildHasher,
3268-
Q: Eq + Hash
3269-
{
3270-
type Key = K;
3271-
3272-
#[inline]
3273-
fn get(&self, key: &Q) -> Option<&K> {
3274-
self.search(key).map(|bucket| bucket.into_refs().0)
3275-
}
3276-
3277-
fn take(&mut self, key: &Q) -> Option<K> {
3278-
self.search_mut(key).map(|bucket| pop_internal(bucket).0)
3279-
}
3280-
3281-
#[inline]
3282-
fn replace(&mut self, key: K) -> Option<K> {
3283-
self.reserve(1);
3284-
3285-
match self.entry(key) {
3286-
Occupied(mut occupied) => {
3287-
let key = occupied.take_key().unwrap();
3288-
Some(mem::replace(occupied.elem.read_mut().0, key))
3289-
}
3290-
Vacant(vacant) => {
3291-
vacant.insert(());
3292-
None
3293-
}
3294-
}
3295-
}
3296-
}
3297-
32983258
#[allow(dead_code)]
32993259
fn assert_covariance() {
33003260
fn map_key<'new>(v: HashMap<&'static str, u8>) -> HashMap<&'new str, u8> {

src/libstd/collections/hash/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ mod bench;
44
mod table;
55
pub mod map;
66
pub mod set;
7-
8-
trait Recover<Q: ?Sized> {
9-
type Key;
10-
11-
fn get(&self, key: &Q) -> Option<&Self::Key>;
12-
fn take(&mut self, key: &Q) -> Option<Self::Key>;
13-
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
14-
}

src/libstd/collections/hash/set.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::hash::{Hash, BuildHasher};
44
use crate::iter::{Chain, FromIterator, FusedIterator};
55
use crate::ops::{BitOr, BitAnd, BitXor, Sub};
66

7-
use super::Recover;
87
use super::map::{self, HashMap, Keys, RandomState};
98

109
// Future Optimization (FIXME!)
@@ -579,7 +578,7 @@ impl<T, S> HashSet<T, S>
579578
where T: Borrow<Q>,
580579
Q: Hash + Eq
581580
{
582-
Recover::get(&self.map, value)
581+
self.map.get_key_value(value).map(|(k, _)| k)
583582
}
584583

585584
/// Returns `true` if `self` has no elements in common with `other`.
@@ -699,7 +698,13 @@ impl<T, S> HashSet<T, S>
699698
/// ```
700699
#[stable(feature = "set_recovery", since = "1.9.0")]
701700
pub fn replace(&mut self, value: T) -> Option<T> {
702-
Recover::replace(&mut self.map, value)
701+
match self.map.entry(value) {
702+
map::Entry::Occupied(occupied) => Some(occupied.replace_key()),
703+
map::Entry::Vacant(vacant) => {
704+
vacant.insert(());
705+
None
706+
}
707+
}
703708
}
704709

705710
/// Removes a value from the set. Returns whether the value was
@@ -754,7 +759,7 @@ impl<T, S> HashSet<T, S>
754759
where T: Borrow<Q>,
755760
Q: Hash + Eq
756761
{
757-
Recover::take(&mut self.map, value)
762+
self.map.remove_entry(value).map(|(k, _)| k)
758763
}
759764

760765
/// Retains only the elements specified by the predicate.

0 commit comments

Comments
 (0)