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

Method value_unchecked

arrow-array/src/array/byte_array.rs:308–333  ·  view source on GitHub ↗

Returns the element at index `i` Note: This method does not check for nulls and the value is arbitrary if [`is_null`](Self::is_null) returns true for the index. # Safety Caller is responsible for ensuring that the index is within the bounds of the array

(&self, i: usize)

Source from the content-addressed store, hash-verified

306 /// # Safety
307 /// Caller is responsible for ensuring that the index is within the bounds of the array
308 pub unsafe fn value_unchecked(&self, i: usize) -> &T::Native {
309 let end = *unsafe { self.value_offsets().get_unchecked(i + 1) };
310 let start = *unsafe { self.value_offsets().get_unchecked(i) };
311
312 // Soundness
313 // pointer alignment & location is ensured by RawPtrBox
314 // buffer bounds/offset is ensured by the value_offset invariants
315
316 // Safety of `to_isize().unwrap()`
317 // `start` and `end` are &OffsetSize, which is a generic type that implements the
318 // OffsetSizeTrait. Currently, only i32 and i64 implement OffsetSizeTrait,
319 // both of which should cleanly cast to isize on an architecture that supports
320 // 32/64-bit offsets
321 let b = unsafe {
322 std::slice::from_raw_parts(
323 self.value_data
324 .as_ptr()
325 .offset(start.to_isize().unwrap_unchecked()),
326 (end - start).to_usize().unwrap_unchecked(),
327 )
328 };
329
330 // SAFETY:
331 // ArrayData is valid
332 unsafe { T::Native::from_bytes_unchecked(b) }
333 }
334
335 /// Returns the element at index `i`
336 ///

Callers 1

valueMethod · 0.45

Calls 5

to_isizeMethod · 0.80
to_usizeMethod · 0.80
value_offsetsMethod · 0.45
offsetMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected