Open an aindrive drive as a read-only folder in Memona #1

Merged
RaymondCho merged 2 commits from read-only-folder into main 2026-10-13 21:52:31 +00:00
Showing only changes of commit 0221f89c00 - Show all commits
+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 /// Sixteen characters go through each step of the main loop, which measured
/// a third cheaper in fuel per character than four at a time. /// a third cheaper in fuel per character than four at a time.
fn groups(chars: &[u8], out: &mut [u8]) -> u32 { fn groups(chars: &[u8], out: &mut [u8]) -> u32 {
let wide = chars.chunks_exact(16); let (wide, rest) = chars.as_chunks::<16>();
let (wide_out, rest_out) = out.split_at_mut(chars.len() / 16 * 12); let (rest, _) = rest.as_chunks::<4>();
let rest = wide.remainder().chunks_exact(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; let mut flags = 0;
for (chars, bytes) in wide.zip(wide_out.chunks_exact_mut(12)) { for (chars, bytes) in wide.iter().zip(wide_out) {
let (Some(low), Some(high)) = let chars = u128::from_le_bytes(*chars);
(chars.first_chunk::<8>(), chars.last_chunk::<8>()) let [a, b, c, d] = [0, 32, 64, 96]
else { .map(|shift| group(((chars >> shift) as u32).to_le_bytes()));
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()));
flags |= a | b | c | d; flags |= a | b | c | d;
let front = u64::from(a) | u64::from(b) << 24 | u64::from(c) << 48; let front = u64::from(a) | u64::from(b) << 24 | u64::from(c) << 48;
let back = c >> 16 | d << 8; let back = c >> 16 | d << 8;
bytes[..8].copy_from_slice(&front.to_le_bytes()); bytes[..8].copy_from_slice(&front.to_le_bytes());
bytes[8..].copy_from_slice(&back.to_le_bytes()); bytes[8..].copy_from_slice(&back.to_le_bytes());
} }
for (chars, bytes) in rest.zip(rest_out.chunks_exact_mut(3)) { for (chars, bytes) in rest.iter().zip(rest_out) {
if let Some(chars) = chars.first_chunk::<4>() {
let word = group(*chars); let word = group(*chars);
flags |= word; flags |= word;
bytes.copy_from_slice(&word.to_le_bytes()[..3]); bytes.copy_from_slice(&word.to_le_bytes()[..3]);
} }
}
flags flags
} }