MCPcopy Create free account
hub / github.com/apache/arrow-rs / get_last_offset

Function get_last_offset

arrow-data/src/transform/utils.rs:49–59  ·  view source on GitHub ↗
(offset_buffer: &MutableBuffer)

Source from the content-addressed store, hash-verified

47
48#[inline]
49pub(super) unsafe fn get_last_offset<T: ArrowNativeType>(offset_buffer: &MutableBuffer) -> T {
50 // JUSTIFICATION
51 // Benefit
52 // 20% performance improvement extend of variable sized arrays (see bench `mutable_array`)
53 // Soundness
54 // * offset buffer is always extended in slices of T and aligned accordingly.
55 // * Buffer[0] is initialized with one element, 0, and thus `mutable_offsets.len() - 1` is always valid.
56 let (prefix, offsets, suffix) = unsafe { offset_buffer.as_slice().align_to::<T>() };
57 debug_assert!(prefix.is_empty() && suffix.is_empty());
58 *unsafe { offsets.get_unchecked(offsets.len() - 1) }
59}
60
61#[cfg(test)]
62mod tests {

Callers 4

build_extendFunction · 0.85
extend_nullsFunction · 0.85
build_extendFunction · 0.85
extend_nullsFunction · 0.85

Calls 2

as_sliceMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected