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

Improved performance of Bitmap::make_mut with offset #1079

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Changes from all commits
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
8 changes: 6 additions & 2 deletions src/bitmap/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;
use crate::{buffer::bytes::Bytes, error::Error, trusted_len::TrustedLen};

use super::{
chunk_iter_to_vec,
utils::{count_zeros, fmt, get_bit, get_bit_unchecked, BitChunk, BitChunks, BitmapIter},
MutableBitmap,
};
Expand Down Expand Up @@ -240,8 +241,11 @@ impl Bitmap {
match self.into_mut() {
Either::Left(data) => {
if data.offset > 0 {
// we have to recreate the bytes because a MutableBitmap does not have an `offset`.
data.iter().collect()
// re-align the bits (remove the offset)
let chunks = data.chunks::<u64>();
let remainder = chunks.remainder();
let vec = chunk_iter_to_vec(chunks.chain(std::iter::once(remainder)));
MutableBitmap::from_vec(vec, data.length)
} else {
MutableBitmap::from_vec(data.bytes.as_ref().to_vec(), data.length)
}
Expand Down