@@ -812,7 +812,7 @@ impl<T> RawTable<T, Global> {
812812 #[ inline]
813813 pub const fn new ( ) -> Self {
814814 Self {
815- table : RawTableInner :: new ( ) ,
815+ table : RawTableInner :: NEW ,
816816 alloc : Global ,
817817 marker : PhantomData ,
818818 }
@@ -844,7 +844,7 @@ impl<T, A: Allocator> RawTable<T, A> {
844844 #[ inline]
845845 pub const fn new_in ( alloc : A ) -> Self {
846846 Self {
847- table : RawTableInner :: new ( ) ,
847+ table : RawTableInner :: NEW ,
848848 alloc,
849849 marker : PhantomData ,
850850 }
@@ -1034,7 +1034,7 @@ impl<T, A: Allocator> RawTable<T, A> {
10341034 // space for.
10351035 let min_size = usize:: max ( self . table . items , min_size) ;
10361036 if min_size == 0 {
1037- let mut old_inner = mem:: replace ( & mut self . table , RawTableInner :: new ( ) ) ;
1037+ let mut old_inner = mem:: replace ( & mut self . table , RawTableInner :: NEW ) ;
10381038 unsafe {
10391039 // SAFETY:
10401040 // 1. We call the function only once;
@@ -1534,7 +1534,7 @@ impl<T, A: Allocator> RawTable<T, A> {
15341534 debug_assert_eq ! ( iter. len( ) , self . len( ) ) ;
15351535 RawDrain {
15361536 iter,
1537- table : mem:: replace ( & mut self . table , RawTableInner :: new ( ) ) ,
1537+ table : mem:: replace ( & mut self . table , RawTableInner :: NEW ) ,
15381538 orig_table : NonNull :: from ( & mut self . table ) ,
15391539 marker : PhantomData ,
15401540 }
@@ -1595,6 +1595,8 @@ where
15951595}
15961596
15971597impl RawTableInner {
1598+ const NEW : Self = RawTableInner :: new ( ) ;
1599+
15981600 /// Creates a new empty hash table without allocating any memory.
15991601 ///
16001602 /// In effect this returns a table with exactly 1 bucket. However we can
@@ -1673,7 +1675,7 @@ impl RawTableInner {
16731675 A : Allocator ,
16741676 {
16751677 if capacity == 0 {
1676- Ok ( Self :: new ( ) )
1678+ Ok ( Self :: NEW )
16771679 } else {
16781680 // SAFETY: We checked that we could successfully allocate the new table, and then
16791681 // initialized all control bytes with the constant `EMPTY` byte.
@@ -2436,20 +2438,17 @@ impl RawTableInner {
24362438 /// and return it inside ScopeGuard to protect against panic in the hash
24372439 /// function.
24382440 ///
2439- /// # Safety:
2440- ///
2441- /// The `alloc` must be the same [`Allocator`] as the `Allocator` used
2442- /// to allocate this table otherwise calling this function may result in
2443- /// [`undefined behavior`].
2444- ///
24452441 /// # Note
24462442 ///
24472443 /// It is recommended (but not required):
24482444 ///
24492445 /// * That the new table's `capacity` be greater than or equal to `self.items`.
24502446 ///
2451- /// * The `table_layout` is the same [`TableLayout`] as the `TableLayout` that
2452- /// was used to allocate this table.
2447+ /// * The `alloc` is the same [`Allocator`] as the `Allocator` used
2448+ /// to allocate this table.
2449+ ///
2450+ /// * The `table_layout` is the same [`TableLayout`] as the `TableLayout` used
2451+ /// to allocate this table.
24532452 ///
24542453 /// If `table_layout` does not match the `TableLayout` that was used to allocate
24552454 /// this table, then using `mem::swap` with the `self` and the new table returned
@@ -2458,7 +2457,7 @@ impl RawTableInner {
24582457 /// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
24592458 #[ allow( clippy:: mut_mut) ]
24602459 #[ inline]
2461- unsafe fn prepare_resize < ' a , A > (
2460+ fn prepare_resize < ' a , A > (
24622461 & self ,
24632462 alloc : & ' a A ,
24642463 table_layout : TableLayout ,
@@ -2484,11 +2483,9 @@ impl RawTableInner {
24842483 if !self_. is_empty_singleton ( ) {
24852484 // SAFETY:
24862485 // 1. We have checked that our table is allocated.
2487- // 2. The caller of this function ensures that `alloc` is the
2488- // same [`Allocator`] used to allocate this table.
2489- // 3. We know for sure that `table_layout` matches the [`TableLayout`]
2490- // used to allocate this table.
2491- self_. free_buckets ( alloc, table_layout) ;
2486+ // 2. We know for sure that the `alloc` and `table_layout` matches the
2487+ // [`Allocator`] and [`TableLayout`] used to allocate this table.
2488+ unsafe { self_. free_buckets ( alloc, table_layout) } ;
24922489 }
24932490 } ) )
24942491 }
@@ -3080,7 +3077,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for RawTable<T, A> {
30803077
30813078 fn clone_from ( & mut self , source : & Self ) {
30823079 if source. table . is_empty_singleton ( ) {
3083- let mut old_inner = mem:: replace ( & mut self . table , RawTableInner :: new ( ) ) ;
3080+ let mut old_inner = mem:: replace ( & mut self . table , RawTableInner :: NEW ) ;
30843081 unsafe {
30853082 // SAFETY:
30863083 // 1. We call the function only once;
0 commit comments