Skip to content

Commit bdef041

Browse files
authored
Improvements to color cache (#101)
1 parent 5a7e16c commit bdef041

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/lossless.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ impl<R: BufRead> LosslessDecoder<R> {
579579
.color_cache
580580
.as_mut()
581581
.ok_or(DecodingError::BitStreamError)?;
582-
data[index * 4..][..4].copy_from_slice(&color_cache.lookup(key.into())?);
582+
data[index * 4..][..4].copy_from_slice(&color_cache.lookup(key.into()));
583583
index += 1;
584584
}
585585
}
@@ -665,6 +665,7 @@ struct ColorCache {
665665
}
666666

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

676-
fn lookup(&self, index: usize) -> Result<[u8; 4], DecodingError> {
677-
match self.color_cache.get(index) {
678-
Some(&value) => Ok(value),
679-
None => Err(DecodingError::BitStreamError),
680-
}
677+
#[inline(always)]
678+
fn lookup(&self, index: usize) -> [u8; 4] {
679+
self.color_cache[index]
681680
}
682681
}
683682

0 commit comments

Comments
 (0)