No bound checks when indexing during decoding

This commit is contained in:
Ivan Smirnov 2021-11-29 04:21:50 +00:00
parent 92a750c2e3
commit cbae67b07d

View file

@ -75,7 +75,10 @@ where
let b1 = buf.read();
match b1 & QOI_MASK_2 {
QOI_INDEX => {
px = index[usize::from(b1 ^ QOI_INDEX)];
px = unsafe {
// Safety: (b1 ^ QOI_INDEX) is guaranteed to be at most 6 bits
*index.get_unchecked(usize::from(b1 ^ QOI_INDEX))
};
}
QOI_DIFF_8 => {
px.rgb_add(