Skip to content

Commit ae0a4f2

Browse files
committed
Call HashTable methods where exact matches exist
1 parent 69c0ab3 commit ae0a4f2

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/map.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
506506
/// Returns a reference to the underlying allocator.
507507
#[inline]
508508
pub fn allocator(&self) -> &A {
509-
self.table.raw.allocator()
509+
self.table.allocator()
510510
}
511511

512512
/// Creates an empty `HashMap` which will use the given hash builder to hash
@@ -614,7 +614,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
614614
/// ```
615615
#[cfg_attr(feature = "inline-more", inline)]
616616
pub fn capacity(&self) -> usize {
617-
self.table.raw.capacity()
617+
self.table.capacity()
618618
}
619619

620620
/// An iterator visiting all keys in arbitrary order.
@@ -807,7 +807,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
807807
#[cfg(test)]
808808
#[cfg_attr(feature = "inline-more", inline)]
809809
fn raw_capacity(&self) -> usize {
810-
self.table.raw.num_buckets()
810+
self.table.num_buckets()
811811
}
812812

813813
/// Returns the number of elements in the map.
@@ -824,7 +824,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
824824
/// ```
825825
#[cfg_attr(feature = "inline-more", inline)]
826826
pub fn len(&self) -> usize {
827-
self.table.raw.len()
827+
self.table.len()
828828
}
829829

830830
/// Returns `true` if the map contains no elements.
@@ -916,15 +916,8 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
916916
where
917917
F: FnMut(&K, &mut V) -> bool,
918918
{
919-
// Here we only use `iter` as a temporary, preventing use-after-free
920-
unsafe {
921-
for item in self.table.raw.iter() {
922-
let &mut (ref key, ref mut value) = item.as_mut();
923-
if !f(key, value) {
924-
self.table.raw.erase(item);
925-
}
926-
}
927-
}
919+
self.table
920+
.retain(move |&mut (ref key, ref mut val)| f(key, val))
928921
}
929922

930923
/// Drains elements which are true under the given predicate,
@@ -1005,7 +998,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
1005998
/// ```
1006999
#[cfg_attr(feature = "inline-more", inline)]
10071000
pub fn clear(&mut self) {
1008-
self.table.raw.clear();
1001+
self.table.clear();
10091002
}
10101003

10111004
/// Creates a consuming iterator visiting all the keys in arbitrary order.
@@ -1304,9 +1297,9 @@ where
13041297
Q: Hash + Equivalent<K> + ?Sized,
13051298
{
13061299
// Avoid `Option::map` because it bloats LLVM IR.
1307-
if !self.table.raw.is_empty() {
1300+
if !self.table.is_empty() {
13081301
let hash = make_hash::<Q, S>(&self.hash_builder, k);
1309-
match self.table.raw.get(hash, equivalent_key(k)) {
1302+
match self.table.find(hash, equivalent_key(k)) {
13101303
Some((_, v)) => Some(v),
13111304
None => None,
13121305
}
@@ -1340,9 +1333,9 @@ where
13401333
Q: Hash + Equivalent<K> + ?Sized,
13411334
{
13421335
// Avoid `Option::map` because it bloats LLVM IR.
1343-
if !self.table.raw.is_empty() {
1336+
if !self.table.is_empty() {
13441337
let hash = make_hash::<Q, S>(&self.hash_builder, k);
1345-
match self.table.raw.get(hash, equivalent_key(k)) {
1338+
match self.table.find(hash, equivalent_key(k)) {
13461339
Some((key, value)) => Some((key, value)),
13471340
None => None,
13481341
}
@@ -1380,9 +1373,9 @@ where
13801373
Q: Hash + Equivalent<K> + ?Sized,
13811374
{
13821375
// Avoid `Option::map` because it bloats LLVM IR.
1383-
if !self.table.raw.is_empty() {
1376+
if !self.table.is_empty() {
13841377
let hash = make_hash::<Q, S>(&self.hash_builder, k);
1385-
match self.table.raw.get_mut(hash, equivalent_key(k)) {
1378+
match self.table.find_mut(hash, equivalent_key(k)) {
13861379
Some(&mut (ref key, ref mut value)) => Some((key, value)),
13871380
None => None,
13881381
}
@@ -1415,9 +1408,9 @@ where
14151408
where
14161409
Q: Hash + Equivalent<K> + ?Sized,
14171410
{
1418-
if !self.table.raw.is_empty() {
1411+
if !self.table.is_empty() {
14191412
let hash = make_hash::<Q, S>(&self.hash_builder, k);
1420-
self.table.raw.get(hash, equivalent_key(k)).is_some()
1413+
self.table.find(hash, equivalent_key(k)).is_some()
14211414
} else {
14221415
false
14231416
}
@@ -1452,9 +1445,9 @@ where
14521445
Q: Hash + Equivalent<K> + ?Sized,
14531446
{
14541447
// Avoid `Option::map` because it bloats LLVM IR.
1455-
if !self.table.raw.is_empty() {
1448+
if !self.table.is_empty() {
14561449
let hash = make_hash::<Q, S>(&self.hash_builder, k);
1457-
match self.table.raw.get_mut(hash, equivalent_key(k)) {
1450+
match self.table.find_mut(hash, equivalent_key(k)) {
14581451
Some(&mut (_, ref mut v)) => Some(v),
14591452
None => None,
14601453
}
@@ -2055,7 +2048,7 @@ where
20552048
/// primarily used for memory profiling.
20562049
#[inline]
20572050
pub fn allocation_size(&self) -> usize {
2058-
self.table.raw.allocation_size()
2051+
self.table.allocation_size()
20592052
}
20602053
}
20612054

0 commit comments

Comments
 (0)