Skip to content

Commit cd0cf99

Browse files
committed
Misc code cleanup
1 parent dc930b0 commit cd0cf99

File tree

7 files changed

+36
-22
lines changed

7 files changed

+36
-22
lines changed

src/map.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,6 @@ where
898898
unsafe {
899899
let hash = make_hash(&self.hash_builder, &k);
900900
if let Some(item) = self.table.find(hash, |x| k.eq(x.0.borrow())) {
901-
// Erase the element from the table first since drop might panic.
902901
self.table.erase_no_drop(&item);
903902
Some(item.read())
904903
} else {
@@ -1568,7 +1567,6 @@ impl<'a, K, V> RawOccupiedEntryMut<'a, K, V> {
15681567
/// Take the ownership of the key and value from the map.
15691568
pub fn remove_entry(self) -> (K, V) {
15701569
unsafe {
1571-
// Erase the element from the table first since drop might panic.
15721570
self.table.erase_no_drop(&self.elem);
15731571
self.elem.read()
15741572
}
@@ -1656,7 +1654,7 @@ pub enum Entry<'a, K: 'a, V: 'a, S: 'a> {
16561654
Vacant(VacantEntry<'a, K, V, S>),
16571655
}
16581656

1659-
impl<'a, K: 'a + Debug + Eq + Hash, V: 'a + Debug, S: BuildHasher> Debug for Entry<'a, K, V, S> {
1657+
impl<'a, K: 'a + Debug + Eq + Hash, V: 'a + Debug, S: 'a> Debug for Entry<'a, K, V, S> {
16601658
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
16611659
match *self {
16621660
Vacant(ref v) => f.debug_tuple("Entry").field(v).finish(),
@@ -1709,7 +1707,7 @@ pub struct VacantEntry<'a, K: 'a, V: 'a, S: 'a> {
17091707
table: &'a mut HashMap<K, V, S>,
17101708
}
17111709

1712-
impl<'a, K: 'a + Debug + Eq + Hash, V: 'a, S: 'a + BuildHasher> Debug for VacantEntry<'a, K, V, S> {
1710+
impl<'a, K: 'a + Debug + Eq + Hash, V: 'a, S> Debug for VacantEntry<'a, K, V, S> {
17131711
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17141712
f.debug_tuple("VacantEntry").field(self.key()).finish()
17151713
}
@@ -1959,7 +1957,7 @@ where
19591957
}
19601958
}
19611959

1962-
impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
1960+
impl<'a, K, V, S> Entry<'a, K, V, S> {
19631961
/// Ensures a value is in the entry by inserting the default if empty, and returns
19641962
/// a mutable reference to the value in the entry.
19651963
///
@@ -1977,7 +1975,11 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
19771975
/// assert_eq!(map["poneyland"], 6);
19781976
/// ```
19791977
#[inline]
1980-
pub fn or_insert(self, default: V) -> &'a mut V {
1978+
pub fn or_insert(self, default: V) -> &'a mut V
1979+
where
1980+
K: Hash,
1981+
S: BuildHasher,
1982+
{
19811983
match self {
19821984
Occupied(entry) => entry.into_mut(),
19831985
Vacant(entry) => entry.insert(default),
@@ -2000,7 +2002,11 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
20002002
/// assert_eq!(map["poneyland"], "hoho".to_string());
20012003
/// ```
20022004
#[inline]
2003-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
2005+
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
2006+
where
2007+
K: Hash,
2008+
S: BuildHasher,
2009+
{
20042010
match self {
20052011
Occupied(entry) => entry.into_mut(),
20062012
Vacant(entry) => entry.insert(default()),
@@ -2060,7 +2066,7 @@ impl<'a, K: Eq + Hash, V, S: BuildHasher> Entry<'a, K, V, S> {
20602066
}
20612067
}
20622068

2063-
impl<'a, K: Eq + Hash, V: Default, S: BuildHasher> Entry<'a, K, V, S> {
2069+
impl<'a, K, V: Default, S> Entry<'a, K, V, S> {
20642070
/// Ensures a value is in the entry by inserting the default value if empty,
20652071
/// and returns a mutable reference to the value in the entry.
20662072
///
@@ -2077,7 +2083,11 @@ impl<'a, K: Eq + Hash, V: Default, S: BuildHasher> Entry<'a, K, V, S> {
20772083
/// # }
20782084
/// ```
20792085
#[inline]
2080-
pub fn or_default(self) -> &'a mut V {
2086+
pub fn or_default(self) -> &'a mut V
2087+
where
2088+
K: Hash,
2089+
S: BuildHasher,
2090+
{
20812091
match self {
20822092
Occupied(entry) => entry.into_mut(),
20832093
Vacant(entry) => entry.insert(Default::default()),
@@ -2123,7 +2133,6 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
21232133
#[inline]
21242134
pub fn remove_entry(self) -> (K, V) {
21252135
unsafe {
2126-
// Erase the element from the table first since drop might panic.
21272136
self.table.table.erase_no_drop(&self.elem);
21282137
self.elem.read()
21292138
}
@@ -2316,7 +2325,7 @@ impl<'a, K, V, S> OccupiedEntry<'a, K, V, S> {
23162325
}
23172326
}
23182327

2319-
impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher> VacantEntry<'a, K, V, S> {
2328+
impl<'a, K: 'a, V: 'a, S> VacantEntry<'a, K, V, S> {
23202329
/// Gets a reference to the key that would be used when inserting a value
23212330
/// through the `VacantEntry`.
23222331
///
@@ -2369,7 +2378,11 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher> VacantEntry<'a, K, V, S> {
23692378
/// assert_eq!(map["poneyland"], 37);
23702379
/// ```
23712380
#[inline]
2372-
pub fn insert(self, value: V) -> &'a mut V {
2381+
pub fn insert(self, value: V) -> &'a mut V
2382+
where
2383+
K: Hash,
2384+
S: BuildHasher,
2385+
{
23732386
let hash_builder = &self.table.hash_builder;
23742387
let bucket = self.table.table.insert(self.hash, (self.key, value), |x| {
23752388
make_hash(hash_builder, &x.0)
@@ -2424,6 +2437,7 @@ where
24242437
V: Copy,
24252438
S: BuildHasher,
24262439
{
2440+
#[inline]
24272441
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T) {
24282442
self.extend(iter.into_iter().map(|(&key, &value)| (key, value)));
24292443
}

src/raw/bitmask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use super::imp::{BitMaskWord, BITMASK_MASK, BITMASK_SHIFT};
12
#[cfg(feature = "nightly")]
23
use core::intrinsics;
3-
use raw::imp::{BitMaskWord, BITMASK_MASK, BITMASK_SHIFT};
44

55
/// A bit mask which contains the result of a `Match` operation on a `Group` and
66
/// allows iterating through them.

src/raw/generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use super::bitmask::BitMask;
2+
use super::EMPTY;
13
use core::{mem, ptr};
2-
use raw::bitmask::BitMask;
3-
use raw::EMPTY;
44

55
// Use the native word size as the group size. Using a 64-bit group size on
66
// a 32-bit architecture will just end up being more expensive because

src/raw/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ mod imp;
5252

5353
mod bitmask;
5454

55-
use raw::bitmask::BitMask;
56-
use raw::imp::Group;
55+
use self::bitmask::BitMask;
56+
use self::imp::Group;
5757

5858
/// Control byte value for an empty bucket.
5959
const EMPTY: u8 = 0b11111111;

src/raw/sse2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use super::bitmask::BitMask;
2+
use super::EMPTY;
13
use core::mem;
2-
use raw::bitmask::BitMask;
3-
use raw::EMPTY;
44

55
#[cfg(target_arch = "x86")]
66
use core::arch::x86;

src/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,8 +1438,8 @@ fn assert_covariance() {
14381438

14391439
#[cfg(test)]
14401440
mod test_set {
1441-
use super::HashSet;
14421441
use super::super::map::DefaultHashBuilder;
1442+
use super::HashSet;
14431443
use std::vec::Vec;
14441444

14451445
#[test]

tests/set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate hashbrown;
22
extern crate rand;
33

44
use hashbrown::HashSet;
5-
use rand::{Rng, SeedableRng, XorShiftRng};
5+
use rand::{Rng, SeedableRng, XorShiftRng, distributions::Alphanumeric};
66

77
#[test]
88
fn test_hashset_insert_remove() {
@@ -16,7 +16,7 @@ fn test_hashset_insert_remove() {
1616
let mut rng: XorShiftRng = SeedableRng::from_seed(seed);
1717
//let mut rng: XorShiftRng = XorShiftRng::new_unseeded();
1818
let tx: Vec<Vec<char>> = (0..4096)
19-
.map(|_| (rng.gen_ascii_chars().take(32).collect()))
19+
.map(|_| (rng.sample_iter(&Alphanumeric).take(32).collect()))
2020
.collect();
2121

2222
for _ in 0..32 {

0 commit comments

Comments
 (0)