This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new c5b4ab1  enhancement: remove redundant if/clamp_min/abs (#1428)
c5b4ab1 is described below

commit c5b4ab1886d08f9cb24980ad275f500f1224d584
Author: jakevin <[email protected]>
AuthorDate: Thu Mar 17 15:35:28 2022 +0800

    enhancement: remove redundant if/clamp_min/abs (#1428)
---
 arrow/src/compute/kernels/window.rs | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/arrow/src/compute/kernels/window.rs 
b/arrow/src/compute/kernels/window.rs
index b425952..54b11c3 100644
--- a/arrow/src/compute/kernels/window.rs
+++ b/arrow/src/compute/kernels/window.rs
@@ -24,7 +24,6 @@ use crate::{
     compute::concat,
 };
 use num::abs;
-use num::traits::clamp_min;
 
 /// Shifts array by defined number of items (to left or right)
 /// A positive value for `offset` shifts the array to the right
@@ -64,18 +63,21 @@ pub fn shift(array: &dyn Array, offset: i64) -> 
Result<ArrayRef> {
     } else if offset == i64::MIN || abs(offset) >= value_len {
         Ok(new_null_array(array.data_type(), array.len()))
     } else {
-        let slice_offset = clamp_min(-offset, 0) as usize;
-        let length = array.len() - abs(offset) as usize;
-        let slice = array.slice(slice_offset, length);
-
-        // Generate array with remaining `null` items
-        let nulls = abs(offset) as usize;
-        let null_arr = new_null_array(array.data_type(), nulls);
-
         // Concatenate both arrays, add nulls after if shift > 0 else before
         if offset > 0 {
+            let length = array.len() - offset as usize;
+            let slice = array.slice(0, length);
+
+            // Generate array with remaining `null` items
+            let null_arr = new_null_array(array.data_type(), offset as usize);
             concat(&[null_arr.as_ref(), slice.as_ref()])
         } else {
+            let offset = -offset as usize;
+            let length = array.len() - offset;
+            let slice = array.slice(offset, length);
+
+            // Generate array with remaining `null` items
+            let null_arr = new_null_array(array.data_type(), offset);
             concat(&[slice.as_ref(), null_arr.as_ref()])
         }
     }

Reply via email to