Lint: as_chunks for constant chunk sizes, as clippy 1.99 asks
Rust 1.99's clippy adds chunks_exact_to_as_chunks, and cargo clippy --workspace --all-targets -D warnings (cargo xtask ci) failed on its eight hits in metafile, pdf and eps. as_chunks gives fixed-size arrays, so the loops read the same bytes without indexing into slices, and encrypt's CBC loop takes the remainder from as_chunks instead of the iterator. as_chunks is stable since 1.88. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U9TrG4w49oSRYbP3cqxA3D
This commit is contained in:
parent
fd99375b1b
commit
945dcbae1d
|
|
@ -429,10 +429,8 @@ impl Interp<'_> {
|
|||
return Err(PsError::Limit("a path has too many points"));
|
||||
}
|
||||
let mut bp = BezPath::new();
|
||||
for r in nums.chunks_exact(4) {
|
||||
if let [x, y, w, h] = r {
|
||||
bp.extend(self.rect_path(*x, *y, *w, *h));
|
||||
}
|
||||
for [x, y, w, h] in nums.as_chunks::<4>().0 {
|
||||
bp.extend(self.rect_path(*x, *y, *w, *h));
|
||||
}
|
||||
Ok(bp)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ pub(crate) fn rgb24(img: &Rgba, opacity: f32) -> (Vec<u8>, Vec<u8>) {
|
|||
// Bottom-up: the first stored row is the image's last.
|
||||
let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue };
|
||||
let Some(dst) = bits.get_mut(at..at + img.width as usize * 3) else { continue };
|
||||
for (d, p) in dst.chunks_exact_mut(3).zip(src.as_chunks::<4>().0) {
|
||||
for (d, p) in dst.as_chunks_mut::<3>().0.iter_mut().zip(src.as_chunks::<4>().0) {
|
||||
let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32;
|
||||
d.copy_from_slice(&[over(p[2], a), over(p[1], a), over(p[0], a)]);
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ pub(crate) fn bgra32(img: &Rgba, opacity: f32) -> (Vec<u8>, Vec<u8>) {
|
|||
for (y, src) in img.pixels.chunks_exact(row.max(1)).enumerate() {
|
||||
let Some(at) = (img.height as usize).checked_sub(y + 1).map(|r| r * row) else { continue };
|
||||
let Some(dst) = bits.get_mut(at..at + row) else { continue };
|
||||
for (d, p) in dst.chunks_exact_mut(4).zip(src.as_chunks::<4>().0) {
|
||||
for (d, p) in dst.as_chunks_mut::<4>().0.iter_mut().zip(src.as_chunks::<4>().0) {
|
||||
let a = (f32::from(p[3]) * opacity.clamp(0.0, 1.0)).round() as u32;
|
||||
let pre = |c: u8| ((u32::from(c) * a + 127) / 255) as u8;
|
||||
d.copy_from_slice(&[pre(p[2]), pre(p[1]), pre(p[0]), a as u8]);
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ impl Player {
|
|||
let mut bp = BezPath::new();
|
||||
bp.move_to(*first);
|
||||
if bezier {
|
||||
for c in rest.chunks_exact(3) {
|
||||
for c in rest.as_chunks::<3>().0 {
|
||||
bp.curve_to(c[0], c[1], c[2]);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -636,7 +636,7 @@ impl Player {
|
|||
}
|
||||
};
|
||||
if bezier {
|
||||
for c in pts.chunks_exact(3) {
|
||||
for c in pts.as_chunks::<3>().0 {
|
||||
target.curve_to(xf * c[0], xf * c[1], xf * c[2]);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ fn record(p: &mut Player, kind: u32, rec: &[u8]) -> Option<()> {
|
|||
let off = r.u32()?;
|
||||
let s = if kind == 84 {
|
||||
let raw = slice(rec, off, u32::try_from(n.checked_mul(2)?).ok()?)?;
|
||||
String::from_utf16_lossy(&raw.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect::<Vec<_>>())
|
||||
String::from_utf16_lossy(&raw.as_chunks::<2>().0.iter().map(|c| u16::from_le_bytes(*c)).collect::<Vec<_>>())
|
||||
} else {
|
||||
slice(rec, off, u32::try_from(n).ok()?)?.iter().map(|b| char::from(*b)).collect()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ pub(crate) fn units_per_inch(w: f64, h: f64) -> u16 {
|
|||
|
||||
/// The XOR of the first ten 16-bit words of a placeable header.
|
||||
pub(crate) fn checksum(header: &[u8]) -> u16 {
|
||||
header.chunks_exact(2).take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes([w[0], w[1]]))
|
||||
header.as_chunks::<2>().0.iter().take(10).fold(0, |acc, w| acc ^ u16::from_le_bytes(*w))
|
||||
}
|
||||
|
||||
/// `bp` flattened to within `tol`: each subpath's points and whether it closes.
|
||||
|
|
|
|||
|
|
@ -232,12 +232,11 @@ impl Aes {
|
|||
prev = self.block(std::array::from_fn(|i| chunk[i] ^ prev[i]));
|
||||
out.extend_from_slice(&prev);
|
||||
};
|
||||
let mut chunks = data.chunks_exact(16);
|
||||
for c in &mut chunks {
|
||||
put(std::array::from_fn(|i| c.get(i).copied().unwrap_or_default()), &mut out);
|
||||
let (chunks, rest) = data.as_chunks::<16>();
|
||||
for c in chunks {
|
||||
put(*c, &mut out);
|
||||
}
|
||||
if pad {
|
||||
let rest = chunks.remainder();
|
||||
let n = (16 - rest.len()) as u8;
|
||||
put(std::array::from_fn(|i| rest.get(i).copied().unwrap_or(n)), &mut out);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue