Skip to content

Minor cleanup of hashmap #7875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/libstd/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,8 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
let len_buckets = self.buckets.len();
let bucket = self.buckets[idx].take();

let value = match bucket {
None => None,
Some(Bucket{value, _}) => {
Some(value)
},
let value = do bucket.map_consume |bucket| {
bucket.value
};

/* re-inserting buckets may cause changes in size, so remember
Expand Down Expand Up @@ -505,7 +502,6 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
// `consume_rev_iter` is more efficient than `consume_iter` for vectors
HashMapConsumeIterator {iter: self.buckets.consume_rev_iter()}
}

}

impl<K: Hash + Eq, V: Clone> HashMap<K, V> {
Expand All @@ -524,14 +520,12 @@ impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
fn eq(&self, other: &HashMap<K, V>) -> bool {
if self.len() != other.len() { return false; }

for self.iter().advance |(key, value)| {
do self.iter().all |(key, value)| {
match other.find(key) {
None => return false,
Some(v) => if value != v { return false },
None => false,
Some(v) => value == v
}
}

true
}

fn ne(&self, other: &HashMap<K, V>) -> bool { !self.eq(other) }
Expand Down