Skip to content

Commit 3e526c4

Browse files
nyurikdanielrh
authored andcommitted
Simplify non-wrapping += and *=
Use this replacement file as described in other recent PRs to replace boilerplate code. Followed by `cargo fmt --all` <details> <summary>replacement file content</summary> ```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; -} ``` </details>
1 parent 6fae4d3 commit 3e526c4

File tree

2 files changed

+5
-23
lines changed

2 files changed

+5
-23
lines changed

src/enc/encode.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,34 +1813,20 @@ fn ChooseContextMap(
18131813
+ ShannonEntropy(&two_prefix_histo[3..], 3usize, &mut dummy);
18141814
entropy[3] = 0i32 as (super::util::floatX);
18151815
for i in 0usize..3usize {
1816-
let _rhs = ShannonEntropy(
1816+
entropy[3] += ShannonEntropy(
18171817
&bigram_histo[(3usize).wrapping_mul(i)..],
18181818
3usize,
18191819
&mut dummy,
18201820
);
1821-
let _lhs = &mut entropy[3];
1822-
*_lhs += _rhs;
18231821
}
18241822
let total: usize = monogram_histo[0]
18251823
.wrapping_add(monogram_histo[1])
18261824
.wrapping_add(monogram_histo[2]) as usize;
18271825
0i32;
18281826
entropy[0] = 1.0 as super::util::floatX / total as (super::util::floatX);
1829-
{
1830-
let _rhs = entropy[0];
1831-
let _lhs = &mut entropy[1];
1832-
*_lhs *= _rhs;
1833-
}
1834-
{
1835-
let _rhs = entropy[0];
1836-
let _lhs = &mut entropy[2];
1837-
*_lhs *= _rhs;
1838-
}
1839-
{
1840-
let _rhs = entropy[0];
1841-
let _lhs = &mut entropy[3];
1842-
*_lhs *= _rhs;
1843-
}
1827+
entropy[1] *= entropy[0];
1828+
entropy[2] *= entropy[0];
1829+
entropy[3] *= entropy[0];
18441830
if quality < 7i32 {
18451831
entropy[3] = entropy[1] * 10i32 as (super::util::floatX);
18461832
}

src/enc/metablock.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,7 @@ fn ContextBlockSplitterFinishBlock<
722722
);
723723
combined_entropy[jx] =
724724
BitsEntropy(combined_histo.slice()[jx].slice(), xself.alphabet_size_);
725-
{
726-
let _rhs = combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
727-
let _lhs = &mut diff[j];
728-
*_lhs += _rhs;
729-
}
725+
diff[j] += combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
730726
}
731727
j = j.wrapping_add(1);
732728
}

0 commit comments

Comments
 (0)