Merge pull request #138 from theironchef/fix/clippy-1.99

Lint: as_chunks for constant chunk sizes, as clippy 1.99 asks
This commit is contained in:
Brandon Thomas authored and GitHub committed 2026-10-05 21:51:22 -04:00
commit 3f0bce6a88
9 files changed
+15 -18

No files matched your search

+1 -1
View File
@@ -1097,7 +1097,7 @@ fn emf_of(records: &[(u32, Vec<u8>)]) -> Vec<u8> {
/// A placeable WMF of a 1 × 1 inch box holding `records`.
fn wmf_of(records: &[(u16, Vec<u8>)]) -> Vec<u8> {
let mut b: Vec<u8> = vec![0xD7, 0xCD, 0xC6, 0x9A, 0, 0, 0, 0, 0, 0, 0xA0, 0x05, 0xA0, 0x05, 0xA0, 0x05, 0, 0, 0, 0];
let sum = b.chunks_exact(2).fold(0u16, |a, w| a ^ u16::from_le_bytes([w[0], w[1]]));
let sum = b.as_chunks::<2>().0.iter().fold(0u16, |a, w| a ^ u16::from_le_bytes(*w));
b.extend(sum.to_le_bytes());
b.extend([1, 0, 9, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
for (function, body) in records {
+2 -4
View File
@@ -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)
}
+2 -2
View File
@@ -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]);
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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()
};
+1 -1
View File
@@ -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.
+3 -4
View File
@@ -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);
}
+1 -1
View File
@@ -166,7 +166,7 @@ fn anti_alias_none_is_the_same_on_every_thread_count() {
};
let (st, mt) = (render(0), render(3));
for img in [&st, &mt] {
assert!(img.to_straight().chunks_exact(4).all(|p| p[3] == 0 || p[3] == 255), "hard edges");
assert!(img.to_straight().as_chunks::<4>().0.iter().all(|p| p[3] == 0 || p[3] == 255), "hard edges");
}
let worst = st.pixels.iter().zip(&mt.pixels).map(|(a, b)| a.abs_diff(*b)).max().unwrap();
assert!(worst <= 4, "max channel difference {worst}");
+2 -2
View File
@@ -259,7 +259,7 @@ fn file_face_names(path: &Path) -> Vec<(String, String)> {
// A collection lists where each face's table directory starts.
let starts: Vec<u32> = if head.starts_with(b"ttcf") {
let n = be32(&head, 8).unwrap_or(0).min(MAX_FACES) as usize;
read_at(12, n * 4).map(|b| b.chunks_exact(4).filter_map(|c| be32(c, 0)).collect()).unwrap_or_default()
read_at(12, n * 4).map(|b| b.as_chunks::<4>().0.iter().map(|c| u32::from_be_bytes(*c)).collect()).unwrap_or_default()
} else {
vec![0]
};
@@ -269,7 +269,7 @@ fn file_face_names(path: &Path) -> Vec<(String, String)> {
let dir = read_at(start.into(), 12)?;
let tables = u16::from_be_bytes(dir.get(4..6)?.try_into().ok()?) as usize;
let records = read_at(u64::from(start) + 12, tables * 16)?;
let rec = records.chunks_exact(16).find(|r| r.starts_with(b"name"))?;
let rec: &[u8] = records.as_chunks::<16>().0.iter().find(|r| r.starts_with(b"name"))?;
let (offset, len) = (be32(rec, 8)?, be32(rec, 12)?);
if len > MAX_NAME_TABLE {
return None;