Skip to content

Commit

Permalink
Add missing inline to ArrowNativeTypeOp (#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Nov 10, 2022
1 parent a0fb44a commit 0e97338
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions arrow-array/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ macro_rules! native_type_op {
const ZERO: Self = $zero;
const ONE: Self = $one;

#[inline]
fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
self.checked_add(rhs).ok_or_else(|| {
ArrowError::ComputeError(format!(
Expand All @@ -105,10 +106,12 @@ macro_rules! native_type_op {
})
}

#[inline]
fn add_wrapping(self, rhs: Self) -> Self {
self.wrapping_add(rhs)
}

#[inline]
fn sub_checked(self, rhs: Self) -> Result<Self, ArrowError> {
self.checked_sub(rhs).ok_or_else(|| {
ArrowError::ComputeError(format!(
Expand All @@ -118,10 +121,12 @@ macro_rules! native_type_op {
})
}

#[inline]
fn sub_wrapping(self, rhs: Self) -> Self {
self.wrapping_sub(rhs)
}

#[inline]
fn mul_checked(self, rhs: Self) -> Result<Self, ArrowError> {
self.checked_mul(rhs).ok_or_else(|| {
ArrowError::ComputeError(format!(
Expand All @@ -131,10 +136,12 @@ macro_rules! native_type_op {
})
}

#[inline]
fn mul_wrapping(self, rhs: Self) -> Self {
self.wrapping_mul(rhs)
}

#[inline]
fn div_checked(self, rhs: Self) -> Result<Self, ArrowError> {
if rhs.is_zero() {
Err(ArrowError::DivideByZero)
Expand All @@ -148,10 +155,12 @@ macro_rules! native_type_op {
}
}

#[inline]
fn div_wrapping(self, rhs: Self) -> Self {
self.wrapping_div(rhs)
}

#[inline]
fn mod_checked(self, rhs: Self) -> Result<Self, ArrowError> {
if rhs.is_zero() {
Err(ArrowError::DivideByZero)
Expand All @@ -165,54 +174,66 @@ macro_rules! native_type_op {
}
}

#[inline]
fn mod_wrapping(self, rhs: Self) -> Self {
self.wrapping_rem(rhs)
}

#[inline]
fn neg_checked(self) -> Result<Self, ArrowError> {
self.checked_neg().ok_or_else(|| {
ArrowError::ComputeError(format!("Overflow happened on: {:?}", self))
})
}

#[inline]
fn pow_checked(self, exp: u32) -> Result<Self, ArrowError> {
self.checked_pow(exp).ok_or_else(|| {
ArrowError::ComputeError(format!("Overflow happened on: {:?}", self))
})
}

#[inline]
fn pow_wrapping(self, exp: u32) -> Self {
self.wrapping_pow(exp)
}

#[inline]
fn neg_wrapping(self) -> Self {
self.wrapping_neg()
}

#[inline]
fn is_zero(self) -> bool {
self == Self::ZERO
}

#[inline]
fn is_eq(self, rhs: Self) -> bool {
self == rhs
}

#[inline]
fn is_ne(self, rhs: Self) -> bool {
self != rhs
}

#[inline]
fn is_lt(self, rhs: Self) -> bool {
self < rhs
}

#[inline]
fn is_le(self, rhs: Self) -> bool {
self <= rhs
}

#[inline]
fn is_gt(self, rhs: Self) -> bool {
self > rhs
}

#[inline]
fn is_ge(self, rhs: Self) -> bool {
self >= rhs
}
Expand All @@ -237,30 +258,37 @@ macro_rules! native_type_float_op {
const ZERO: Self = $zero;
const ONE: Self = $one;

#[inline]
fn add_checked(self, rhs: Self) -> Result<Self, ArrowError> {
Ok(self + rhs)
}

#[inline]
fn add_wrapping(self, rhs: Self) -> Self {
self + rhs
}

#[inline]
fn sub_checked(self, rhs: Self) -> Result<Self, ArrowError> {
Ok(self - rhs)
}

#[inline]
fn sub_wrapping(self, rhs: Self) -> Self {
self - rhs
}

#[inline]
fn mul_checked(self, rhs: Self) -> Result<Self, ArrowError> {
Ok(self * rhs)
}

#[inline]
fn mul_wrapping(self, rhs: Self) -> Self {
self * rhs
}

#[inline]
fn div_checked(self, rhs: Self) -> Result<Self, ArrowError> {
if rhs.is_zero() {
Err(ArrowError::DivideByZero)
Expand All @@ -269,10 +297,12 @@ macro_rules! native_type_float_op {
}
}

#[inline]
fn div_wrapping(self, rhs: Self) -> Self {
self / rhs
}

#[inline]
fn mod_checked(self, rhs: Self) -> Result<Self, ArrowError> {
if rhs.is_zero() {
Err(ArrowError::DivideByZero)
Expand All @@ -281,53 +311,65 @@ macro_rules! native_type_float_op {
}
}

#[inline]
fn mod_wrapping(self, rhs: Self) -> Self {
self % rhs
}

#[inline]
fn neg_checked(self) -> Result<Self, ArrowError> {
Ok(-self)
}

#[inline]
fn neg_wrapping(self) -> Self {
-self
}

#[inline]
fn pow_checked(self, exp: u32) -> Result<Self, ArrowError> {
Ok(self.powi(exp as i32))
}

#[inline]
fn pow_wrapping(self, exp: u32) -> Self {
self.powi(exp as i32)
}

#[inline]
fn is_zero(self) -> bool {
self == $zero
}

#[inline]
fn is_eq(self, rhs: Self) -> bool {
// Equivalent to `self.total_cmp(&rhs).is_eq()`
// but LLVM isn't able to realise this is bitwise equality
// https://rust.godbolt.org/z/347nWGxoW
self.to_bits() == rhs.to_bits()
}

#[inline]
fn is_ne(self, rhs: Self) -> bool {
!self.is_eq(rhs)
}

#[inline]
fn is_lt(self, rhs: Self) -> bool {
self.total_cmp(&rhs).is_lt()
}

#[inline]
fn is_le(self, rhs: Self) -> bool {
self.total_cmp(&rhs).is_le()
}

#[inline]
fn is_gt(self, rhs: Self) -> bool {
self.total_cmp(&rhs).is_gt()
}

#[inline]
fn is_ge(self, rhs: Self) -> bool {
self.total_cmp(&rhs).is_ge()
}
Expand Down

0 comments on commit 0e97338

Please sign in to comment.