You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2019/02/11 10:22:26 UTC
[arrow] branch master updated: ARROW-4489: [Rust]
PrimitiveArray.value_slice performs bounds checking when it should not
This is an automated email from the ASF dual-hosted git repository.
kszucs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 133d402 ARROW-4489: [Rust] PrimitiveArray.value_slice performs bounds checking when it should not
133d402 is described below
commit 133d4022bb7bd2df665a46f19fa40324ef1c5911
Author: Paddy Horan <pa...@hotmail.com>
AuthorDate: Mon Feb 11 11:22:15 2019 +0100
ARROW-4489: [Rust] PrimitiveArray.value_slice performs bounds checking when it should not
If you run the following test it will fail:
```rust
#[test]
fn test_value_slice() {
let arr = Int32Array::from(vec![2, 3, 4]);
let _slice = arr.value_slice(0, 4);
}
```
When working with SIMD I plan to rely on the fact that we have buffers padded to a multiple of 64 bytes. This makes the implementation easier to maintain and more efficient. However, it involves reading and writing to the padded region.
Author: Paddy Horan <pa...@hotmail.com>
Closes #3569 from paddyhoran/value_slice_fix and squashes the following commits:
5f93b76b <Paddy Horan> Added test for no bounds checking.
5340a01f <Paddy Horan> Removed bounds checking on `value_slice`
---
rust/arrow/src/array.rs | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/rust/arrow/src/array.rs b/rust/arrow/src/array.rs
index 127edb9..c887ab7 100644
--- a/rust/arrow/src/array.rs
+++ b/rust/arrow/src/array.rs
@@ -236,8 +236,10 @@ impl<T: ArrowNumericType> PrimitiveArray<T> {
///
/// Note this doesn't do any bound checking, for performance reason.
pub fn value_slice(&self, offset: usize, len: usize) -> &[T::Native] {
- let raw = unsafe { std::slice::from_raw_parts(self.raw_values(), self.len()) };
- &raw[offset..offset + len]
+ let raw = unsafe {
+ std::slice::from_raw_parts(self.raw_values().offset(offset as isize), len)
+ };
+ &raw[..]
}
// Returns a new primitive array builder
@@ -754,6 +756,12 @@ mod tests {
}
#[test]
+ fn test_value_slice_no_bounds_check() {
+ let arr = Int32Array::from(vec![2, 3, 4]);
+ let _slice = arr.value_slice(0, 4);
+ }
+
+ #[test]
fn test_primitive_array_builder() {
// Test building an primitive array with ArrayData builder and offset
let buf = Buffer::from(&[0, 1, 2, 3, 4].to_byte_slice());