@@ -812,7 +812,7 @@ impl<T> RawTable<T, Global> {
812
812
#[ inline]
813
813
pub const fn new ( ) -> Self {
814
814
Self {
815
- table : RawTableInner :: new ( ) ,
815
+ table : RawTableInner :: NEW ,
816
816
alloc : Global ,
817
817
marker : PhantomData ,
818
818
}
@@ -844,7 +844,7 @@ impl<T, A: Allocator> RawTable<T, A> {
844
844
#[ inline]
845
845
pub const fn new_in ( alloc : A ) -> Self {
846
846
Self {
847
- table : RawTableInner :: new ( ) ,
847
+ table : RawTableInner :: NEW ,
848
848
alloc,
849
849
marker : PhantomData ,
850
850
}
@@ -1034,7 +1034,7 @@ impl<T, A: Allocator> RawTable<T, A> {
1034
1034
// space for.
1035
1035
let min_size = usize:: max ( self . table . items , min_size) ;
1036
1036
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 ) ;
1038
1038
unsafe {
1039
1039
// SAFETY:
1040
1040
// 1. We call the function only once;
@@ -1534,7 +1534,7 @@ impl<T, A: Allocator> RawTable<T, A> {
1534
1534
debug_assert_eq ! ( iter. len( ) , self . len( ) ) ;
1535
1535
RawDrain {
1536
1536
iter,
1537
- table : mem:: replace ( & mut self . table , RawTableInner :: new ( ) ) ,
1537
+ table : mem:: replace ( & mut self . table , RawTableInner :: NEW ) ,
1538
1538
orig_table : NonNull :: from ( & mut self . table ) ,
1539
1539
marker : PhantomData ,
1540
1540
}
@@ -1595,6 +1595,8 @@ where
1595
1595
}
1596
1596
1597
1597
impl RawTableInner {
1598
+ const NEW : Self = RawTableInner :: new ( ) ;
1599
+
1598
1600
/// Creates a new empty hash table without allocating any memory.
1599
1601
///
1600
1602
/// In effect this returns a table with exactly 1 bucket. However we can
@@ -1673,7 +1675,7 @@ impl RawTableInner {
1673
1675
A : Allocator ,
1674
1676
{
1675
1677
if capacity == 0 {
1676
- Ok ( Self :: new ( ) )
1678
+ Ok ( Self :: NEW )
1677
1679
} else {
1678
1680
// SAFETY: We checked that we could successfully allocate the new table, and then
1679
1681
// initialized all control bytes with the constant `EMPTY` byte.
@@ -2436,20 +2438,17 @@ impl RawTableInner {
2436
2438
/// and return it inside ScopeGuard to protect against panic in the hash
2437
2439
/// function.
2438
2440
///
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
- ///
2445
2441
/// # Note
2446
2442
///
2447
2443
/// It is recommended (but not required):
2448
2444
///
2449
2445
/// * That the new table's `capacity` be greater than or equal to `self.items`.
2450
2446
///
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.
2453
2452
///
2454
2453
/// If `table_layout` does not match the `TableLayout` that was used to allocate
2455
2454
/// this table, then using `mem::swap` with the `self` and the new table returned
@@ -2458,7 +2457,7 @@ impl RawTableInner {
2458
2457
/// [`undefined behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
2459
2458
#[ allow( clippy:: mut_mut) ]
2460
2459
#[ inline]
2461
- unsafe fn prepare_resize < ' a , A > (
2460
+ fn prepare_resize < ' a , A > (
2462
2461
& self ,
2463
2462
alloc : & ' a A ,
2464
2463
table_layout : TableLayout ,
@@ -2484,11 +2483,9 @@ impl RawTableInner {
2484
2483
if !self_. is_empty_singleton ( ) {
2485
2484
// SAFETY:
2486
2485
// 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) } ;
2492
2489
}
2493
2490
} ) )
2494
2491
}
@@ -3080,7 +3077,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for RawTable<T, A> {
3080
3077
3081
3078
fn clone_from ( & mut self , source : & Self ) {
3082
3079
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 ) ;
3084
3081
unsafe {
3085
3082
// SAFETY:
3086
3083
// 1. We call the function only once;
0 commit comments