@@ -245,20 +245,21 @@ impl<T> RawTable<T> {
245
245
return self . insert ( hash, value, hasher) ;
246
246
}
247
247
248
- let bucket = if cfg ! ( debug_assertions) {
249
- let buckets = self . table . buckets ( ) ;
250
- let b = self . table . insert ( hash, value, & hasher) ;
251
-
252
- // make sure table didn't resize
253
- assert_eq ! (
254
- buckets,
255
- self . table. buckets( ) ,
256
- "resize while elements are still left over"
257
- ) ;
258
- b
259
- } else {
260
- self . table . insert ( hash, value, & hasher)
261
- } ;
248
+ self . insert_no_grow ( hash, value, hasher)
249
+ }
250
+
251
+ /// Inserts a new element into the table, without growing the table.
252
+ ///
253
+ /// There must be enough space in the table to insert the new element.
254
+ ///
255
+ /// This does not check if the given element already exists in the table.
256
+ ///
257
+ /// Note that unlike `hashbrown::RawTable::insert_no_grow`, this _does_ take a `hasher`.
258
+ /// This is because while the insert won't grow the table, it may need to carry over some
259
+ /// elements from the pre-resize table to the current table, which requires re-hashing.
260
+ #[ cfg_attr( feature = "inline-more" , inline) ]
261
+ pub fn insert_no_grow ( & mut self , hash : u64 , value : T , hasher : impl Fn ( & T ) -> u64 ) -> Bucket < T > {
262
+ let bucket = self . table . insert_no_grow ( hash, value) ;
262
263
263
264
if self . leftovers . is_some ( ) {
264
265
// Also carry some items over.
@@ -477,7 +478,7 @@ impl<T> RawTable<T> {
477
478
// to the resized map, without shrinking the old map.
478
479
let value = unsafe { lo. table . remove ( e) } ;
479
480
let hash = hasher ( & value) ;
480
- self . table . insert ( hash, value, & hasher ) ;
481
+ self . table . insert_no_grow ( hash, value) ;
481
482
} else {
482
483
// The resize is finally fully complete.
483
484
let _ = self . leftovers . take ( ) ;
0 commit comments