@@ -406,6 +406,19 @@ impl<T> RawTable<T, Global> {
406
406
alloc : Global ,
407
407
}
408
408
}
409
+
410
+ /// Attempts to allocate a new hash table with at least enough capacity
411
+ /// for inserting the given number of elements without reallocating.
412
+ #[ cfg( feature = "raw" ) ]
413
+ pub fn try_with_capacity ( capacity : usize ) -> Result < Self , TryReserveError > {
414
+ Self :: try_with_capacity_in ( capacity, Global )
415
+ }
416
+
417
+ /// Allocates a new hash table with at least enough capacity for inserting
418
+ /// the given number of elements without reallocating.
419
+ pub fn with_capacity ( capacity : usize ) -> Self {
420
+ Self :: with_capacity_in ( capacity, Global )
421
+ }
409
422
}
410
423
411
424
impl < T , A : Allocator + Clone > RawTable < T , A > {
@@ -483,16 +496,16 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
483
496
}
484
497
}
485
498
486
- /// Attempts to allocate a new hash table with at least enough capacity
487
- /// for inserting the given number of elements without reallocating.
499
+ /// Attempts to allocate a new hash table using the given allocator, with at least enough
500
+ /// capacity for inserting the given number of elements without reallocating.
488
501
#[ cfg( feature = "raw" ) ]
489
- pub fn try_with_capacity ( alloc : A , capacity : usize ) -> Result < Self , TryReserveError > {
502
+ pub fn try_with_capacity_in ( capacity : usize , alloc : A ) -> Result < Self , TryReserveError > {
490
503
Self :: fallible_with_capacity ( alloc, capacity, Fallibility :: Fallible )
491
504
}
492
505
493
- /// Allocates a new hash table with at least enough capacity for inserting
494
- /// the given number of elements without reallocating.
495
- pub fn with_capacity ( alloc : A , capacity : usize ) -> Self {
506
+ /// Allocates a new hash table using the given allocator, with at least enough capacity for
507
+ /// inserting the given number of elements without reallocating.
508
+ pub fn with_capacity_in ( capacity : usize , alloc : A ) -> Self {
496
509
// Avoid `Result::unwrap_or_else` because it bloats LLVM IR.
497
510
match Self :: fallible_with_capacity ( alloc, capacity, Fallibility :: Infallible ) {
498
511
Ok ( capacity) => capacity,
@@ -748,7 +761,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
748
761
if min_buckets < self . buckets ( ) {
749
762
// Fast path if the table is empty
750
763
if self . items == 0 {
751
- * self = Self :: with_capacity ( self . alloc . clone ( ) , min_size )
764
+ * self = Self :: with_capacity_in ( min_size , self . alloc . clone ( ) )
752
765
} else {
753
766
// Avoid `Result::unwrap_or_else` because it bloats LLVM IR.
754
767
if self
0 commit comments