Skip to content

Commit

Permalink
Refactor Bitmap::new (#1343)
Browse files Browse the repository at this point in the history
### Which issue does this PR close?

Closes #1337.

### Rationale for this change
 
`bit_util` has provided some functions to calculate the ceiling and multiple, so we can use them in `Bitmap::new` to achieve a faster and cleaner code.

### What changes are included in this PR?

### Are there any user-facing changes?

None.
  • Loading branch information
HaoYang670 committed Feb 21, 2022
1 parent f84c436 commit 89ee9ac
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions arrow/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ pub struct Bitmap {

impl Bitmap {
pub fn new(num_bits: usize) -> Self {
let num_bytes = num_bits / 8 + if num_bits % 8 > 0 { 1 } else { 0 };
let r = num_bytes % 64;
let len = if r == 0 {
num_bytes
} else {
num_bytes + 64 - r
};
let num_bytes = bit_util::ceil(num_bits, 8);
let len = bit_util::round_upto_multiple_of_64(num_bytes);
Bitmap {
bits: Buffer::from(&vec![0xFF; len]),
}
Expand Down

0 comments on commit 89ee9ac

Please sign in to comment.