Decode base64 through fixed-size chunks, as clippy 1.99 asks
CI / checks (pull_request) Successful in 1m26s
Agents / bot (pull_request) Successful in 7m28s

CI builds with the newest stable toolchain, whose clippy rejects
chunks_exact with a constant size in favour of as_chunks. The fixed-size
arrays also drop the let-else that could never fail, and a 1 MiB read
now measures 13.3M fuel instead of 13.5M.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 23:26:24 +09:00
parent 3c2cd123b7
commit 0221f89c00
+10 -16
View File
@@ -49,33 +49,27 @@ fn group(chars: [u8; 4]) -> u32 {
/// Sixteen characters go through each step of the main loop, which measured
/// a third cheaper in fuel per character than four at a time.
fn groups(chars: &[u8], out: &mut [u8]) -> u32 {
let wide = chars.chunks_exact(16);
let (wide_out, rest_out) = out.split_at_mut(chars.len() / 16 * 12);
let rest = wide.remainder().chunks_exact(4);
let (wide, rest) = chars.as_chunks::<16>();
let (rest, _) = rest.as_chunks::<4>();
let (wide_out, rest_out) = out.split_at_mut(wide.len() * 12);
let (wide_out, _) = wide_out.as_chunks_mut::<12>();
let (rest_out, _) = rest_out.as_chunks_mut::<3>();
let mut flags = 0;
for (chars, bytes) in wide.zip(wide_out.chunks_exact_mut(12)) {
let (Some(low), Some(high)) =
(chars.first_chunk::<8>(), chars.last_chunk::<8>())
else {
continue;
};
let low = u64::from_le_bytes(*low);
let high = u64::from_le_bytes(*high);
let [a, b, c, d] = [low, low >> 32, high, high >> 32]
.map(|half| group((half as u32).to_le_bytes()));
for (chars, bytes) in wide.iter().zip(wide_out) {
let chars = u128::from_le_bytes(*chars);
let [a, b, c, d] = [0, 32, 64, 96]
.map(|shift| group(((chars >> shift) as u32).to_le_bytes()));
flags |= a | b | c | d;
let front = u64::from(a) | u64::from(b) << 24 | u64::from(c) << 48;
let back = c >> 16 | d << 8;
bytes[..8].copy_from_slice(&front.to_le_bytes());
bytes[8..].copy_from_slice(&back.to_le_bytes());
}
for (chars, bytes) in rest.zip(rest_out.chunks_exact_mut(3)) {
if let Some(chars) = chars.first_chunk::<4>() {
for (chars, bytes) in rest.iter().zip(rest_out) {
let word = group(*chars);
flags |= word;
bytes.copy_from_slice(&word.to_le_bytes()[..3]);
}
}
flags
}