From 3e526c4cdc027ccc3b421236e8214a31f9f6bb12 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 18 Mar 2024 11:28:31 -0400 Subject: [PATCH] Simplify non-wrapping += and *= Use this replacement file as described in other recent PRs to replace boilerplate code. Followed by `cargo fmt --all`
replacement file content ```diff @@ expression expr_r, expr_l; @@ -{ - let _rhs = expr_r; - let _lhs = &mut expr_l; - *_lhs *= _rhs; +expr_l *= expr_r; -} @@ expression expr_r, expr_l, i, start, end; @@ for i in start..end { - let _rhs = expr_r; - let _lhs = &mut expr_l; - *_lhs += _rhs; +expr_l += expr_r; } @@ expression expr_r, expr_l; @@ -{ - let _rhs = expr_r; - let _lhs = &mut expr_l; - *_lhs += _rhs; +expr_l += expr_r; -} ```
--- src/enc/encode.rs | 22 ++++------------------ src/enc/metablock.rs | 6 +----- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/enc/encode.rs b/src/enc/encode.rs index 44b1a789..66677785 100755 --- a/src/enc/encode.rs +++ b/src/enc/encode.rs @@ -1813,34 +1813,20 @@ fn ChooseContextMap( + ShannonEntropy(&two_prefix_histo[3..], 3usize, &mut dummy); entropy[3] = 0i32 as (super::util::floatX); for i in 0usize..3usize { - let _rhs = ShannonEntropy( + entropy[3] += ShannonEntropy( &bigram_histo[(3usize).wrapping_mul(i)..], 3usize, &mut dummy, ); - let _lhs = &mut entropy[3]; - *_lhs += _rhs; } let total: usize = monogram_histo[0] .wrapping_add(monogram_histo[1]) .wrapping_add(monogram_histo[2]) as usize; 0i32; entropy[0] = 1.0 as super::util::floatX / total as (super::util::floatX); - { - let _rhs = entropy[0]; - let _lhs = &mut entropy[1]; - *_lhs *= _rhs; - } - { - let _rhs = entropy[0]; - let _lhs = &mut entropy[2]; - *_lhs *= _rhs; - } - { - let _rhs = entropy[0]; - let _lhs = &mut entropy[3]; - *_lhs *= _rhs; - } + entropy[1] *= entropy[0]; + entropy[2] *= entropy[0]; + entropy[3] *= entropy[0]; if quality < 7i32 { entropy[3] = entropy[1] * 10i32 as (super::util::floatX); } diff --git a/src/enc/metablock.rs b/src/enc/metablock.rs index 95986e10..99a2441c 100755 --- a/src/enc/metablock.rs +++ b/src/enc/metablock.rs @@ -722,11 +722,7 @@ fn ContextBlockSplitterFinishBlock< ); combined_entropy[jx] = BitsEntropy(combined_histo.slice()[jx].slice(), xself.alphabet_size_); - { - let _rhs = combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx]; - let _lhs = &mut diff[j]; - *_lhs += _rhs; - } + diff[j] += combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx]; } j = j.wrapping_add(1); }