Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/lossless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl<R: BufRead> LosslessDecoder<R> {
.color_cache
.as_mut()
.ok_or(DecodingError::BitStreamError)?;
data[index * 4..][..4].copy_from_slice(&color_cache.lookup(key.into())?);
data[index * 4..][..4].copy_from_slice(&color_cache.lookup(key.into()));
index += 1;
}
}
Expand Down Expand Up @@ -665,6 +665,7 @@ struct ColorCache {
}

impl ColorCache {
#[inline(always)]
fn insert(&mut self, color: [u8; 4]) {
let [r, g, b, a] = color;
let color_u32 =
Expand All @@ -673,11 +674,9 @@ impl ColorCache {
self.color_cache[index as usize] = color;
}

fn lookup(&self, index: usize) -> Result<[u8; 4], DecodingError> {
match self.color_cache.get(index) {
Some(&value) => Ok(value),
None => Err(DecodingError::BitStreamError),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch should actually be unreachable because only valid indexes can be represented in the bitstream, so I've converted it to a panic

}
#[inline(always)]
fn lookup(&self, index: usize) -> [u8; 4] {
self.color_cache[index]
}
}

Expand Down