Skip to content

Commit

Permalink
Minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
maj160 authored and shssoichiro committed Jan 19, 2023
1 parent bc10ebc commit 8978707
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/context/transform_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,10 @@ impl<'a> ContextWriter<'a> {
) {
// Coefficients and levels are transposed from how they work in the spec
for (coeffs_col, levels_col) in
coeffs.chunks(height).zip(levels.chunks_mut(levels_stride))
coeffs.chunks_exact(height).zip(levels.chunks_exact_mut(levels_stride))
{
for (coeff, level) in coeffs_col.iter().zip(levels_col.iter_mut()) {
*level = clamp(coeff.abs(), T::cast_from(0), T::cast_from(127)).as_();
for (coeff, level) in coeffs_col.iter().zip(levels_col) {
*level = coeff.abs().min(T::cast_from(127)).as_();
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,8 @@ pub(crate) mod rust {
let mut sum_s2: u32 = 0; // sum(src_{i,j}^2)
let mut sum_d2: u32 = 0; // sum(dst_{i,j}^2)
let mut sum_sd: u32 = 0; // sum(src_{i,j} * dst_{i,j})
for j in 0..h {
let row1 = &src[j][0..w];
let row2 = &dst[j][0..w];
for (s, d) in row1.iter().zip(row2) {
for (row1, row2) in src.rows_iter().take(h).zip(dst.rows_iter()) {
for (s, d) in row1[..w].iter().zip(row2) {
let s: u32 = u32::cast_from(*s);
let d: u32 = u32::cast_from(*d);
sum_s += s;
Expand Down

0 comments on commit 8978707

Please sign in to comment.