Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
simplify the way to get offsets. No performance penalty

Signed-off-by: remzi <[email protected]>
  • Loading branch information
HaoYang670 committed Mar 24, 2022
1 parent af7c4e5 commit 7183822
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions arrow/src/compute/kernels/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ use crate::{

macro_rules! unary_offsets {
($array: expr, $data_type: expr, $op: expr) => {{
// note: offsets are stored as u8, but they can be interpreted as OffsetSize
let offsets = &$array.data_ref().buffers()[0];
// this is a 30% improvement over iterating over u8s and building OffsetSize, which
// justifies the usage of `unsafe`.
let slice: &[O] = &unsafe { offsets.typed_data::<O>() }[$array.offset()..];
let slice = $array.value_offsets();

let lengths = slice.windows(2).map(|offset| $op(offset[1] - offset[0]));

Expand Down Expand Up @@ -114,7 +110,7 @@ where
unary_offsets!(array, T::DATA_TYPE, |x| x * bits_in_bytes)
}

/// Returns an array of Int32/Int64 denoting the number of bytes in each string in the array.
/// Returns an array of Int32/Int64 denoting the number of bytes in each value in the array.
///
/// * this only accepts StringArray/Utf8, LargeString/LargeUtf8, BinaryArray and LargeBinaryArray
/// * length of null is null.
Expand All @@ -132,7 +128,7 @@ pub fn length(array: &dyn Array) -> Result<ArrayRef> {
}
}

/// Returns an array of Int32/Int64 denoting the number of bits in each string in the array.
/// Returns an array of Int32/Int64 denoting the number of bits in each value in the array.
///
/// * this only accepts StringArray/Utf8, LargeString/LargeUtf8, BinaryArray and LargeBinaryArray
/// * bit_length of null is null.
Expand Down

0 comments on commit 7183822

Please sign in to comment.