Skip to content

Commit

Permalink
Use new methods in hashbrown 0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Jul 16, 2020
1 parent 603c326 commit 1999fa2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ serde = { version = "1.0", optional = true, default-features = false }
rayon = { version = "1.0", optional = true }

[dependencies.hashbrown]
version = "0.8"
version = "0.8.1"
default-features = false
features = ["raw"]

Expand Down
2 changes: 1 addition & 1 deletion src/map/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<K, V> IndexMapCore<K, V> {
debug_assert!(self.indices.capacity() >= self.entries.len());
for (i, entry) in enumerate(&self.entries) {
// We should never have to reallocate, so there's no need for a real hasher.
self.indices.insert(entry.hash.get(), i, |_| unreachable!());
self.indices.insert_no_grow(entry.hash.get(), i);
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/map/core/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<K, V> IndexMapCore<K, V> {

pub(super) fn erase_index(&mut self, hash: HashValue, index: usize) {
let raw_bucket = self.find_index(hash, index).unwrap();
unsafe { self.indices.erase_no_drop(&raw_bucket) };
unsafe { self.indices.erase(raw_bucket) };
}

pub(crate) fn entry(&mut self, hash: HashValue, key: K) -> Entry<K, V>
Expand Down Expand Up @@ -99,10 +99,7 @@ impl<K, V> IndexMapCore<K, V> {
unsafe fn shift_remove_bucket(&mut self, raw_bucket: RawBucket) -> (usize, K, V) {
// use Vec::remove, but then we need to update the indices that point
// to all of the other entries that have to move
let index = unsafe {
self.indices.erase_no_drop(&raw_bucket);
raw_bucket.read()
};
let index = unsafe { self.indices.remove(raw_bucket) };
let entry = self.entries.remove(index);

// correct indices that point to the entries that followed the removed entry.
Expand Down Expand Up @@ -160,10 +157,7 @@ impl<K, V> IndexMapCore<K, V> {
unsafe fn swap_remove_bucket(&mut self, raw_bucket: RawBucket) -> (usize, K, V) {
// use swap_remove, but then we need to update the index that points
// to the other entry that has to move
let index = unsafe {
self.indices.erase_no_drop(&raw_bucket);
raw_bucket.read()
};
let index = unsafe { self.indices.remove(raw_bucket) };
let entry = self.entries.swap_remove(index);

// correct index that points to the entry that had to swap places
Expand Down

0 comments on commit 1999fa2

Please sign in to comment.