Skip to content

Commit 7deb4b5

Browse files
committed
Simplify non-wrapping += and *=
Use this replacement file as described in other recent PRs to replace boilerplate code. <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; @@ -{ - let _rhs = expr_r; - let _lhs = &mut expr_l; - *_lhs += _rhs; +expr_l += expr_r; -} ``` </details>
1 parent b9a4857 commit 7deb4b5

File tree

4 files changed

+15
-33
lines changed

4 files changed

+15
-33
lines changed

src/enc/encode.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,37 +1819,21 @@ fn ChooseContextMap(
18191819
entropy[3] = 0i32 as (super::util::floatX);
18201820
i = 0usize;
18211821
while i < 3usize {
1822-
{
1823-
let _rhs = ShannonEntropy(
1824-
&bigram_histo[(3usize).wrapping_mul(i)..],
1825-
3usize,
1826-
&mut dummy,
1827-
);
1828-
let _lhs = &mut entropy[3];
1829-
*_lhs += _rhs;
1830-
}
1822+
entropy[3] += ShannonEntropy(
1823+
&bigram_histo[(3usize).wrapping_mul(i)..],
1824+
3usize,
1825+
&mut dummy,
1826+
);
18311827
i = i.wrapping_add(1);
18321828
}
18331829
let total: usize = monogram_histo[0]
18341830
.wrapping_add(monogram_histo[1])
18351831
.wrapping_add(monogram_histo[2]) as usize;
18361832
0i32;
18371833
entropy[0] = 1.0 as super::util::floatX / total as (super::util::floatX);
1838-
{
1839-
let _rhs = entropy[0];
1840-
let _lhs = &mut entropy[1];
1841-
*_lhs *= _rhs;
1842-
}
1843-
{
1844-
let _rhs = entropy[0];
1845-
let _lhs = &mut entropy[2];
1846-
*_lhs *= _rhs;
1847-
}
1848-
{
1849-
let _rhs = entropy[0];
1850-
let _lhs = &mut entropy[3];
1851-
*_lhs *= _rhs;
1852-
}
1834+
entropy[1] *= entropy[0];
1835+
entropy[2] *= entropy[0];
1836+
entropy[3] *= entropy[0];
18531837
if quality < 7i32 {
18541838
entropy[3] = entropy[1] * 10i32 as (super::util::floatX);
18551839
}

src/enc/metablock.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,7 @@ fn ContextBlockSplitterFinishBlock<
732732
);
733733
combined_entropy[jx] =
734734
BitsEntropy(combined_histo.slice()[jx].slice(), xself.alphabet_size_);
735-
{
736-
let _rhs = combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
737-
let _lhs = &mut diff[j];
738-
*_lhs += _rhs;
739-
}
735+
diff[j] += combined_entropy[jx] - entropy[i] - xself.last_entropy_[jx];
740736
}
741737
j = j.wrapping_add(1);
742738
}

src/enc/test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ fn oneshot_compress(
5858
unsafe { define_allocator_memory_pool!(96, u64, [0; 32 * 1024], calloc) };
5959
let stack_f64_buffer =
6060
unsafe { define_allocator_memory_pool!(48, super::util::floatX, [0; 128 * 1024], calloc) };
61-
let mut stack_global_buffer_v8 = define_allocator_memory_pool!(64, v8, [v8::default(); 1024 * 16], stack);
61+
let mut stack_global_buffer_v8 =
62+
define_allocator_memory_pool!(64, v8, [v8::default(); 1024 * 16], stack);
6263
let mf8 = StackAllocatedFreelist64::<v8>::new_allocator(&mut stack_global_buffer_v8, bzero);
63-
let mut stack_16x16_buffer = define_allocator_memory_pool!(64, s16, [s16::default(); 1024 * 16], stack);
64+
let mut stack_16x16_buffer =
65+
define_allocator_memory_pool!(64, s16, [s16::default(); 1024 * 16], stack);
6466
let m16x16 = StackAllocatedFreelist64::<s16>::new_allocator(&mut stack_16x16_buffer, bzero);
6567

6668
let stack_hl_buffer =

src/enc/vectorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(unknown_lints)]
22
#![allow(unused_macros)]
33

4-
use enc::util::FastLog2;
5-
use enc::{s8, v8};
64
#[cfg(feature = "simd")]
75
use core::simd::Simd;
6+
use enc::util::FastLog2;
7+
use enc::{s8, v8};
88
pub type Mem256f = v8;
99
pub type Mem256i = s8;
1010
pub type v256 = v8;

0 commit comments

Comments
 (0)