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

Commit

Permalink
Improved performance of make_mut of sliced (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jun 18, 2022
1 parent d4873fc commit 6717786
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 6717786

Please sign in to comment.