anyone have an idea how I can make the looping in this code prettier (without making the code slower (it's currently very well vectorized by the compiler)
fn fetch_packages_apk() -> Result<String, Error> {
//commented out because slow
//let buf = read("/lib/apk/db/installed")?;
//let packages = find_iter(&buf, b"\nP").count();
let buf = read_fast("/lib/apk/db/installed")?;
let mut packages = 0;
let mut chunks0 = buf[..buf.len()-1].chunks_exact(8192);
let mut chunks1 = buf[1..].chunks_exact(8192);
while let (Some(chunk0), Some(chunk1)) = (chunks0.next(), chunks1.next()) {
let mut counters: [u8; 32] = [0; 32];
for j in 0..256 {
for i in 0..32 {
counters[i] += (chunk0[j * 32 + i] == b'\n') as u8 & (chunk1[j * 32 + i] == b'P') as u8;
}
// inner loop should be vectorized as 4 instructions
//compare
//compare
//and
//sub
}
packages += counters.iter().map(|&x| x as usize).sum::<usize>();
}
for (a,b) in chunks0.remainder().iter().zip(chunks1.remainder()) {
packages += (*a == b'\n') as usize & (*b == b'P') as usize;
}
Ok(packages.to_string())
}