[style](trx-ftx): use iterators in LDPC single-index loops
CI / lint (pull_request) Successful in 2m35s
CI / test (pull_request) Successful in 3m22s
CI / reuse (pull_request) Successful in 7s
CI / lint (push) Successful in 2m34s
CI / test (push) Successful in 3m26s
CI / reuse (push) Successful in 7s

clippy needless_range_loop (rust 1.97) flagged the loops in ldpc_check
and ldpc_decode that use a range only to index one array. Replace them
with iterator/enumerate forms. The belief-propagation loops that index
several arrays by the same variable are left as-is (not flagged).

Behaviour is unchanged; the transformations are index-for-index
equivalent. Verified the lib compiles and is clippy-clean; the crate's
LDPC tests run in the CI test job (they need a dev-dependency not
available in the local offline sandbox).

Assisted-By: Claude Code (claude-opus-4)
Claude-Session: https://claude.ai/code/session_01NFpGtGTWUEYXLwZeZs2RAV
Signed-off-by: Stan Grams <sjg@haxx.space>
This commit was merged in pull request #2.
This commit is contained in:
sjg
2026-07-18 10:43:01 +02:00
parent 977f7b709e
commit 4b17b4ac1d
+12 -12
View File
@@ -42,8 +42,8 @@ pub(crate) fn ldpc_check(codeword: &[u8; FTX_LDPC_N]) -> i32 {
for m in 0..FTX_LDPC_M {
let mut x: u8 = 0;
let num_rows = FTX_LDPC_NUM_ROWS[m] as usize;
for i in 0..num_rows {
x ^= codeword[FTX_LDPC_NM[m][i] as usize - 1];
for &nm in FTX_LDPC_NM[m].iter().take(num_rows) {
x ^= codeword[nm as usize - 1];
}
if x != 0 {
errors += 1;
@@ -81,11 +81,11 @@ pub fn ldpc_decode(
for j in 0..FTX_LDPC_M {
let num_rows = FTX_LDPC_NUM_ROWS[j] as usize;
let m_row = j * FTX_LDPC_N;
for ii1 in 0..num_rows {
let i1 = FTX_LDPC_NM[j][ii1] as usize - 1;
for &nm1 in FTX_LDPC_NM[j].iter().take(num_rows) {
let i1 = nm1 as usize - 1;
let mut a = 1.0f32;
for ii2 in 0..num_rows {
let i2 = FTX_LDPC_NM[j][ii2] as usize - 1;
for &nm2 in FTX_LDPC_NM[j].iter().take(num_rows) {
let i2 = nm2 as usize - 1;
if i2 != i1 {
a *= fast_tanh(-m_matrix[m_row + i2] / 2.0f32);
}
@@ -97,8 +97,8 @@ pub fn ldpc_decode(
// Hard decisions
for i in 0..FTX_LDPC_N {
let mut l = codeword[i];
for j in 0..3 {
l += e_matrix[(FTX_LDPC_MN[i][j] as usize - 1) * FTX_LDPC_N + i];
for &mn in FTX_LDPC_MN[i].iter().take(3) {
l += e_matrix[(mn as usize - 1) * FTX_LDPC_N + i];
}
plain[i] = if l > 0.0 { 1 } else { 0 };
}
@@ -113,12 +113,12 @@ pub fn ldpc_decode(
// Update m[][] from e[][]
for i in 0..FTX_LDPC_N {
for ji1 in 0..3 {
let j1 = FTX_LDPC_MN[i][ji1] as usize - 1;
for (ji1, &mn1) in FTX_LDPC_MN[i].iter().enumerate().take(3) {
let j1 = mn1 as usize - 1;
let mut l = codeword[i];
for ji2 in 0..3 {
for (ji2, &mn2) in FTX_LDPC_MN[i].iter().enumerate().take(3) {
if ji1 != ji2 {
let j2 = FTX_LDPC_MN[i][ji2] as usize - 1;
let j2 = mn2 as usize - 1;
l += e_matrix[j2 * FTX_LDPC_N + i];
}
}