From 4c118b3109e173fbb14b3cd91157e58848bc48be Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Thu, 23 Jun 2022 11:15:34 +0800 Subject: [PATCH] replace checked_add(sub).unwrap() with +(-) Signed-off-by: remzi <13716567376yh@gmail.com> --- arrow/src/array/array_binary.rs | 6 +++--- arrow/src/array/data.rs | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs index 481ea92d66c..c0e834f8175 100644 --- a/arrow/src/array/array_binary.rs +++ b/arrow/src/array/array_binary.rs @@ -459,7 +459,7 @@ impl FixedSizeBinaryArray { i < self.data.len(), "FixedSizeBinaryArray out of bounds access" ); - let offset = i.checked_add(self.data.offset()).unwrap(); + let offset = i + self.data.offset(); unsafe { let pos = self.value_offset_at(offset); std::slice::from_raw_parts( @@ -473,7 +473,7 @@ impl FixedSizeBinaryArray { /// # Safety /// Caller is responsible for ensuring that the index is within the bounds of the array pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] { - let offset = i.checked_add(self.data.offset()).unwrap(); + let offset = i + self.data.offset(); let pos = self.value_offset_at(offset); std::slice::from_raw_parts( self.value_data.as_ptr().offset(pos as isize), @@ -779,7 +779,7 @@ impl DecimalArray { /// Returns the element at index `i`. pub fn value(&self, i: usize) -> Decimal128 { assert!(i < self.data.len(), "DecimalArray out of bounds access"); - let offset = i.checked_add(self.data.offset()).unwrap(); + let offset = i + self.data.offset(); let raw_val = unsafe { let pos = self.value_offset_at(offset); std::slice::from_raw_parts( diff --git a/arrow/src/array/data.rs b/arrow/src/array/data.rs index 3e7e6649616..95c980bab6b 100644 --- a/arrow/src/array/data.rs +++ b/arrow/src/array/data.rs @@ -40,8 +40,7 @@ pub(crate) fn count_nulls( len: usize, ) -> usize { if let Some(buf) = null_bit_buffer { - len.checked_sub(buf.count_set_bits_offset(offset, len)) - .unwrap() + len - buf.count_set_bits_offset(offset, len) } else { 0 }