From a469a871d116fda99b82380fe4e8d00a620e7645 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Thu, 13 Aug 2026 16:51:01 +0900 Subject: [PATCH] sort: simplify loop & 2 if blocks --- src/uu/sort/src/sort.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index ef816006b09..b289c8ff760 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -2937,20 +2937,14 @@ fn salt_from_random_source(path: &Path) -> UResult<[u8; SALT_LEN]> { // freeze seed for --random-source let mut hasher = FoldHasher::with_seed(1, SharedSeed::global_fixed()); - loop { - let n = reader - .read(&mut buf) - .map_err(|error| SortError::ReadFailed { - path: path.to_owned(), - error, - })?; - if n == 0 { - break; - } - let remaining = MAX_BYTES.saturating_sub(total); - if remaining == 0 { - break; - } + while let n @ 1.. = reader + .read(&mut buf) + .map_err(|error| SortError::ReadFailed { + path: path.to_owned(), + error, + })? + && let remaining @ 1.. = MAX_BYTES.saturating_sub(total) + { let take = n.min(remaining); hasher.write(&buf[..take]); total = total.saturating_add(take);