Skip to content

Commit

Permalink
Avoid refilling in get_copy_distance (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fintelia authored Aug 6, 2024
1 parent 35885c6 commit ff49006
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lossless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ impl<R: Read> LosslessDecoder<R> {
let extra_bits: u8 = ((prefix_code - 2) >> 1).try_into().unwrap();
let offset = (2 + (usize::from(prefix_code) & 1)) << extra_bits;

Ok(offset + bit_reader.read_bits::<usize>(extra_bits)? + 1)
let bits = bit_reader.peek(extra_bits) as usize;
bit_reader.consume(extra_bits)?;

Ok(offset + bits + 1)
}

/// Gets distance to pixel
Expand Down

0 comments on commit ff49006

Please sign in to comment.