Skip to content

Commit 4a951a3

Browse files
committed
Deprecate set_bits in favor of apply_bitwise_binary_op
1 parent f8d9572 commit 4a951a3

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

arrow-buffer/src/util/bit_mask.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
//! Utils for working with packed bit masks
1919
20-
use crate::bit_util::ceil;
20+
use crate::bit_chunk_iterator::BitChunks;
21+
use crate::bit_util::{apply_bitwise_binary_op, ceil};
2122

2223
/// Util function to set bits in a slice of bytes.
2324
///
@@ -32,28 +33,20 @@ pub fn set_bits(
3233
offset_read: usize,
3334
len: usize,
3435
) -> usize {
35-
assert!(offset_write + len <= write_data.len() * 8);
36-
assert!(offset_read + len <= data.len() * 8);
37-
let mut null_count = 0;
38-
let mut acc = 0;
39-
while len > acc {
40-
// SAFETY: the arguments to `set_upto_64bits` are within the valid range because
41-
// (offset_write + acc) + (len - acc) == offset_write + len <= write_data.len() * 8
42-
// (offset_read + acc) + (len - acc) == offset_read + len <= data.len() * 8
43-
let (n, len_set) = unsafe {
44-
set_upto_64bits(
45-
write_data,
46-
data,
47-
offset_write + acc,
48-
offset_read + acc,
49-
len - acc,
50-
)
51-
};
52-
null_count += n;
53-
acc += len_set;
54-
}
55-
56-
null_count
36+
apply_bitwise_binary_op(
37+
write_data,
38+
offset_write,
39+
data,
40+
offset_read,
41+
len,
42+
|_a, b| b, // copy bits from to_set
43+
);
44+
45+
// TODO move this into a function in bit_utils (and refactor BooleanArray to use it)
46+
// count zero bits in data[offset_read..offset_read+len]
47+
let chunks = BitChunks::new(data, offset_read, len);
48+
let num_ones: usize = chunks.iter_padded().map(|a| a.count_ones() as usize).sum();
49+
len - num_ones
5750
}
5851

5952
/// Similar to `set_bits` but sets only upto 64 bits, actual number of bits set may vary.

arrow-data/src/ffi.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ unsafe extern "C" fn release_array(array: *mut FFI_ArrowArray) {
8686
}
8787

8888
/// Aligns the provided `nulls` to the provided `data_offset`
89-
///
90-
/// This is a temporary measure until offset is removed from ArrayData (#1799)
9189
fn align_nulls(data_offset: usize, nulls: Option<&NullBuffer>) -> Option<Buffer> {
9290
let nulls = nulls?;
9391
if data_offset == nulls.offset() {

0 commit comments

Comments
 (0)