Skip to content

Commit deaa66f

Browse files
committed
Add clear method to avoid new allocations
1 parent d0e7322 commit deaa66f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/bitmap/store/bitmap_store.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,15 @@ impl BitmapStore {
303303
&self.bits
304304
}
305305

306+
pub fn clear(&mut self) {
307+
self.bits.fill(0);
308+
self.len = 0;
309+
}
310+
306311
/// Set N bits that are currently 1 bit from the lower bit to 0.
307312
pub fn remove_front(&mut self, mut clear_bits: u64) {
308313
if self.len() < clear_bits {
309-
*self = Self::default();
314+
self.clear();
310315
return;
311316
}
312317
self.len -= clear_bits as u64;
@@ -337,7 +342,7 @@ impl BitmapStore {
337342
/// Set N bits that are currently 1 bit from the lower bit to 0.
338343
pub fn remove_back(&mut self, mut clear_bits: u64) {
339344
if self.len() < clear_bits {
340-
*self = Self::default();
345+
self.clear();
341346
return;
342347
}
343348
self.len -= clear_bits;

0 commit comments

Comments
 (0)