From 95ee5d3c5736ad6a08fa4d70287ad0d56a74a8f7 Mon Sep 17 00:00:00 2001 From: Will Jones Date: Mon, 18 Sep 2023 01:36:34 -0700 Subject: [PATCH] feat: FixedSizeBinaryArray::value_data return reference (#4821) * feat: FixedSizeBinaryArray::value_data return reference * pr feedback --- arrow-array/src/array/fixed_size_binary_array.rs | 15 ++++++++++++--- arrow-string/src/substring.rs | 3 +-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arrow-array/src/array/fixed_size_binary_array.rs b/arrow-array/src/array/fixed_size_binary_array.rs index 74a7c4c7a84..f0b04c203ce 100644 --- a/arrow-array/src/array/fixed_size_binary_array.rs +++ b/arrow-array/src/array/fixed_size_binary_array.rs @@ -179,9 +179,18 @@ impl FixedSizeBinaryArray { self.value_length } - /// Returns a clone of the value data buffer - pub fn value_data(&self) -> Buffer { - self.value_data.clone() + /// Returns the values of this array. + /// + /// Unlike [`Self::value_data`] this returns the [`Buffer`] + /// allowing for zero-copy cloning. + #[inline] + pub fn values(&self) -> &Buffer { + &self.value_data + } + + /// Returns the raw value data. + pub fn value_data(&self) -> &[u8] { + self.value_data.as_slice() } /// Returns a zero-copy slice of this array with the indicated offset and length. diff --git a/arrow-string/src/substring.rs b/arrow-string/src/substring.rs index 1075d106911..dc0dfdcbb4a 100644 --- a/arrow-string/src/substring.rs +++ b/arrow-string/src/substring.rs @@ -347,8 +347,7 @@ fn fixed_size_binary_substring( // build value buffer let num_of_elements = array.len(); - let values = array.value_data(); - let data = values.as_slice(); + let data = array.value_data(); let mut new_values = MutableBuffer::new(num_of_elements * (new_len as usize)); (0..num_of_elements) .map(|idx| {