|
1 | 1 | use crate::raw::utils::MapGuard; |
2 | | -use crate::raw::{self, InsertResult}; |
| 2 | +use crate::raw::{map, map::InsertResult}; |
3 | 3 | use crate::Equivalent; |
4 | 4 | use seize::{Collector, Guard, LocalGuard, OwnedGuard}; |
5 | 5 |
|
6 | 6 | use std::collections::hash_map::RandomState; |
7 | 7 | use std::fmt; |
8 | 8 | use std::hash::{BuildHasher, Hash}; |
9 | 9 | use std::marker::PhantomData; |
10 | | -use std::mem::ManuallyDrop; |
11 | 10 |
|
12 | 11 | /// A concurrent hash table. |
13 | 12 | /// |
14 | 13 | /// Most hash table operations require a [`Guard`](crate::Guard), which can be acquired through |
15 | 14 | /// [`HashMap::guard`] or using the [`HashMap::pin`] API. See the [crate-level documentation](crate#usage) |
16 | 15 | /// for details. |
17 | 16 | pub struct HashMap<K, V, S = RandomState> { |
18 | | - raw: ManuallyDrop<raw::HashMap<K, V, S>>, |
19 | | -} |
20 | | - |
21 | | -impl<K, V, S> Drop for HashMap<K, V, S> { |
22 | | - fn drop(&mut self) { |
23 | | - // Safety: We don't access `self` after taking the inner map. |
24 | | - raw::drop_map(unsafe { ManuallyDrop::take(&mut self.raw) }); |
25 | | - } |
| 17 | + raw: map::HashMap<K, V, S>, |
26 | 18 | } |
27 | 19 |
|
28 | 20 | // Safety: `HashMap` acts as a single-threaded collection on a single thread. |
@@ -139,12 +131,7 @@ impl<K, V, S> HashMapBuilder<K, V, S> { |
139 | 131 | /// Construct a [`HashMap`] from the builder, using the configured options. |
140 | 132 | pub fn build(self) -> HashMap<K, V, S> { |
141 | 133 | HashMap { |
142 | | - raw: ManuallyDrop::new(raw::HashMap::new( |
143 | | - self.capacity, |
144 | | - self.hasher, |
145 | | - self.collector, |
146 | | - self.resize_mode, |
147 | | - )), |
| 134 | + raw: map::HashMap::new(self.capacity, self.hasher, self.collector, self.resize_mode), |
148 | 135 | } |
149 | 136 | } |
150 | 137 | } |
@@ -264,7 +251,7 @@ impl<K, V, S> HashMap<K, V, S> { |
264 | 251 | /// |
265 | 252 | /// Warning: `hash_builder` is normally randomly generated, and is designed |
266 | 253 | /// to allow HashMaps to be resistant to attacks that cause many collisions |
267 | | - /// and very actuallypoor performance. Setting it manually using this function can |
| 254 | + /// and very poor performance. Setting it manually using this function can |
268 | 255 | /// expose a DoS attack vector. |
269 | 256 | /// |
270 | 257 | /// The `hash_builder` passed should implement the [`BuildHasher`] trait for |
@@ -311,12 +298,12 @@ impl<K, V, S> HashMap<K, V, S> { |
311 | 298 | /// ``` |
312 | 299 | pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> HashMap<K, V, S> { |
313 | 300 | HashMap { |
314 | | - raw: ManuallyDrop::new(raw::HashMap::new( |
| 301 | + raw: map::HashMap::new( |
315 | 302 | capacity, |
316 | 303 | hash_builder, |
317 | 304 | Collector::default(), |
318 | 305 | ResizeMode::default(), |
319 | | - )), |
| 306 | + ), |
320 | 307 | } |
321 | 308 | } |
322 | 309 |
|
@@ -1133,13 +1120,8 @@ impl<K, V, S> IntoIterator for HashMap<K, V, S> { |
1133 | 1120 | /// let v: Vec<(&str, i32)> = map.into_iter().collect(); |
1134 | 1121 | /// ``` |
1135 | 1122 | fn into_iter(self) -> Self::IntoIter { |
1136 | | - let mut map = ManuallyDrop::new(self); |
1137 | | - |
1138 | | - // Safety: We don't access `self` after taking the inner map. |
1139 | | - let raw = unsafe { ManuallyDrop::take(&mut map.raw) }; |
1140 | | - |
1141 | 1123 | IntoIter { |
1142 | | - raw: raw.into_iter(), |
| 1124 | + raw: self.raw.into_iter(), |
1143 | 1125 | } |
1144 | 1126 | } |
1145 | 1127 | } |
@@ -1650,7 +1632,7 @@ where |
1650 | 1632 | /// |
1651 | 1633 | /// This struct is created by the [`iter`](HashMap::iter) method on [`HashMap`]. See its documentation for details. |
1652 | 1634 | pub struct Iter<'g, K, V, G> { |
1653 | | - raw: raw::Iter<'g, K, V, MapGuard<G>>, |
| 1635 | + raw: map::Iter<'g, K, V, MapGuard<G>>, |
1654 | 1636 | } |
1655 | 1637 |
|
1656 | 1638 | impl<'g, K: 'g, V: 'g, G> Iterator for Iter<'g, K, V, G> |
@@ -1688,7 +1670,7 @@ where |
1688 | 1670 | /// |
1689 | 1671 | /// This struct is created by the [`iter_mut`](HashMap::iter_mut) method on [`HashMap`]. See its documentation for details. |
1690 | 1672 | pub struct IterMut<'map, K, V> { |
1691 | | - raw: raw::IterMut<'map, K, V>, |
| 1673 | + raw: map::IterMut<'map, K, V>, |
1692 | 1674 | } |
1693 | 1675 |
|
1694 | 1676 | impl<'map, K, V> Iterator for IterMut<'map, K, V> { |
@@ -1779,7 +1761,7 @@ where |
1779 | 1761 | /// |
1780 | 1762 | /// [`into_iter`]: IntoIterator::into_iter |
1781 | 1763 | pub struct IntoIter<K, V> { |
1782 | | - pub(crate) raw: raw::IntoIter<K, V>, |
| 1764 | + pub(crate) raw: map::IntoIter<K, V>, |
1783 | 1765 | } |
1784 | 1766 |
|
1785 | 1767 | impl<K, V> Iterator for IntoIter<K, V> { |
|
0 commit comments