Skip to content

Commit f688c1c

Browse files
committed
Use the correct function to reserve space for layers
Layer::grow relies on reserving exactly as many bytes as specified in the argument. And it apparently has worked as long as the argument was a power of 2, which it was. This has changed for small vectors since: rust-lang/rust#72227 The fix is to use `reserve_exact` instead.
1 parent 84ece04 commit f688c1c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl Layer {
10371037

10381038
let mut vec =
10391039
mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(self.bits, self.cap, self.cap) });
1040-
vec.reserve(new - self.cap);
1040+
vec.reserve_exact(new - self.cap);
10411041

10421042
// Initialize new values.
10431043
for _ in self.cap..new {
@@ -1705,4 +1705,13 @@ mod tests {
17051705
);
17061706
assert_eq!(std::usize::MAX, round_capacity_up((1usize << 63) + 1));
17071707
}
1708+
1709+
#[test]
1710+
fn test_grow_one_at_a_time() {
1711+
let mut active = BitSet::new();
1712+
1713+
for i in 0..128 {
1714+
active.reserve(i);
1715+
}
1716+
}
17081717
}

0 commit comments

Comments
 (0)