Skip to content

Commit 99a7e3e

Browse files
author
Markus Westerlind
committed
Try specializing the drop in rehash_in_place again
1 parent cae5a3a commit 99a7e3e

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/raw/mod.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,20 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
704704
// that we haven't rehashed yet. We unfortunately can't preserve the
705705
// element since we lost their hash and have no way of recovering it
706706
// without risking another panic.
707-
let mut guard = self.table.prepare_rehash_in_place(
708-
mem::needs_drop::<T>(),
709-
|self_: &mut RawTableInner<A>, index| {
710-
self_.bucket::<T>(index).drop();
711-
},
712-
);
707+
self.table.prepare_rehash_in_place();
708+
709+
let mut guard = guard(&mut self.table, move |self_| {
710+
if mem::needs_drop::<T>() {
711+
for i in 0..self_.buckets() {
712+
if *self_.ctrl(i) == DELETED {
713+
self_.set_ctrl(i, EMPTY);
714+
self_.bucket::<T>(i).drop();
715+
self_.items -= 1;
716+
}
717+
}
718+
}
719+
self_.growth_left = bucket_mask_to_capacity(self_.bucket_mask) - self_.items;
720+
});
713721

714722
// At this point, DELETED elements are elements that we haven't
715723
// rehashed yet. Find them and re-insert them at their ideal
@@ -1170,16 +1178,9 @@ impl<A: Allocator + Clone> RawTableInner<A> {
11701178
}
11711179
}
11721180

1173-
// We use `fn` argument here for `drop` as the function will only be called if the `hasher`
1174-
// panics which should be exceptionally rare. In return we only instantiate a single
1175-
// `prepare_rehash_in_place` per allocator (instead of per type and allocator)
11761181
#[allow(clippy::mut_mut)]
11771182
#[inline]
1178-
unsafe fn prepare_rehash_in_place<'s>(
1179-
&'s mut self,
1180-
needs_drop: bool,
1181-
drop: fn(&mut Self, usize),
1182-
) -> crate::scopeguard::ScopeGuard<&mut Self, impl FnMut(&mut &'s mut Self) + 's> {
1183+
unsafe fn prepare_rehash_in_place(&mut self) {
11831184
// Bulk convert all full control bytes to DELETED, and all DELETED
11841185
// control bytes to EMPTY. This effectively frees up all buckets
11851186
// containing a DELETED entry.
@@ -1198,18 +1199,6 @@ impl<A: Allocator + Clone> RawTableInner<A> {
11981199
self.ctrl(0)
11991200
.copy_to(self.ctrl(self.buckets()), Group::WIDTH);
12001201
}
1201-
guard(self, move |self_| {
1202-
if needs_drop {
1203-
for i in 0..self_.buckets() {
1204-
if *self_.ctrl(i) == DELETED {
1205-
self_.set_ctrl(i, EMPTY);
1206-
drop(self_, i);
1207-
self_.items -= 1;
1208-
}
1209-
}
1210-
}
1211-
self_.growth_left = bucket_mask_to_capacity(self_.bucket_mask) - self_.items;
1212-
})
12131202
}
12141203

12151204
#[cfg_attr(feature = "inline-more", inline)]

0 commit comments

Comments
 (0)