Skip to content

Commit

Permalink
refactor: replace unchecked_subtract_impl with slice_ops::sub
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWhite2357 committed Dec 16, 2024
1 parent 906337b commit 8933493
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions crates/proof-of-sql/src/sql/proof_exprs/comparison_util.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
use crate::{
base::{
database::{Column, ColumnarValue, LiteralValue},
if_rayon,
math::decimal::{DecimalError, Precision},
scalar::{Scalar, ScalarExt},
slice_ops,
},
sql::parse::{type_check_binary_operation, ConversionError, ConversionResult},
};
use alloc::string::ToString;
use bumpalo::Bump;
use core::cmp::{max, Ordering};
#[cfg(feature = "rayon")]
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
use sqlparser::ast::BinaryOperator;

#[allow(clippy::unnecessary_wraps)]
fn unchecked_subtract_impl<'a, S: Scalar>(
alloc: &'a Bump,
lhs: &[S],
rhs: &[S],
table_length: usize,
) -> ConversionResult<&'a [S]> {
let result = alloc.alloc_slice_fill_default(table_length);
if_rayon!(result.par_iter_mut(), result.iter_mut())
.zip(lhs)
.zip(rhs)
.for_each(|((a, l), r)| {
*a = *l - *r;
});
Ok(result)
}

/// Scale LHS and RHS to the same scale if at least one of them is decimal
/// and take the difference. This function is used for comparisons.
///
Expand Down Expand Up @@ -155,12 +136,13 @@ pub(crate) fn scale_and_subtract<'a, S: Scalar>(
}
})?;
}
unchecked_subtract_impl(
alloc,
let result = alloc.alloc_slice_fill_default(lhs_len);
slice_ops::sub(
result,
&lhs.to_scalar_with_scaling(lhs_upscale),
&rhs.to_scalar_with_scaling(rhs_upscale),
lhs_len,
)
);
Ok(result)
}

#[allow(clippy::cast_sign_loss)]
Expand Down

0 comments on commit 8933493

Please sign in to comment.