Skip to content

Commit 50f2ece

Browse files
committed
Special case clear() on empty tables
1 parent f2f2882 commit 50f2ece

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/raw/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,10 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
10271027
/// Removes all elements from the table without freeing the backing memory.
10281028
#[cfg_attr(feature = "inline-more", inline)]
10291029
pub fn clear(&mut self) {
1030+
if self.is_empty() {
1031+
// Special case empty table to avoid surprising O(capacity) time.
1032+
return;
1033+
}
10301034
// Ensure that the table is reset even if one of the drops panic
10311035
let mut self_ = guard(self, |self_| self_.clear_no_drop());
10321036
unsafe {

0 commit comments

Comments
 (0)