You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/06/23 12:47:12 UTC

[arrow-rs] branch master updated: replace checked_add(sub).unwrap() with +(-) (#1924)

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

tustvold 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 c65bbc501 replace checked_add(sub).unwrap() with +(-) (#1924)
c65bbc501 is described below

commit c65bbc50187cd5346bb0ba534280a0688dac4f9b
Author: Remzi Yang <59...@users.noreply.github.com>
AuthorDate: Thu Jun 23 20:47:08 2022 +0800

    replace checked_add(sub).unwrap() with +(-) (#1924)
    
    Signed-off-by: remzi <13...@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 3efb25888..8846b0c97 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 3e7e66496..95c980bab 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
     }