Skip to content

Commit 09cbd95

Browse files
Restructure early break in recreate_vacant_list() (#132)
1 parent 559207c commit 09cbd95

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,21 @@ impl<T> Slab<T> {
442442
self.next = self.entries.len();
443443
// We can stop once we've found all vacant entries
444444
let mut remaining_vacant = self.entries.len() - self.len;
445+
if remaining_vacant == 0 {
446+
return;
447+
}
448+
445449
// Iterate in reverse order so that lower keys are at the start of
446450
// the vacant list. This way future shrinks are more likely to be
447451
// able to remove vacant entries.
448452
for (i, entry) in self.entries.iter_mut().enumerate().rev() {
449-
if remaining_vacant == 0 {
450-
break;
451-
}
452453
if let Entry::Vacant(ref mut next) = *entry {
453454
*next = self.next;
454455
self.next = i;
455456
remaining_vacant -= 1;
457+
if remaining_vacant == 0 {
458+
break;
459+
}
456460
}
457461
}
458462
}

0 commit comments

Comments
 (0)