Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

add new_constant for Bitmap #1579

Merged
merged 10 commits into from
Oct 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
improve bitmap slice_unchecked
  • Loading branch information
Dousir9 committed Oct 3, 2023
commit f702d1acb6082eed1ad3af375d05e5b1eacc7797
9 changes: 6 additions & 3 deletions src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ impl Bitmap {
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
// first guard a no-op slice so that we don't do a bitcount
// if there isn't any data sliced
if !(offset == 0 && length == self.length) {
if !(offset == 0 && length == self.length
|| self.unset_bits == 0
|| self.unset_bits == self.length)
{
// count the smallest chunk
if length < self.length / 2 {
// count the null values in the slice
Expand All @@ -186,9 +189,9 @@ impl Bitmap {
let tail_count = count_zeros(&self.bytes, start_end, self.length - length - offset);
self.unset_bits -= head_count + tail_count;
}
self.offset += offset;
self.length = length;
}
self.offset += offset;
self.length = length;
}

/// Slices `self`, offsetting by `offset` and truncating up to `length` bits.
Expand Down