Skip to content

Commit d1e7e35

Browse files
authored
Merge pull request #57 from image-rs/optimize-symbols-before-size-switch
Optimize size switching to wrapping sub
2 parents 17f4125 + 37c6cb7 commit d1e7e35

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/decode.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,12 @@ impl<C: CodeBuffer, CgC: CodegenConstants> Stateful for DecodeState<C, CgC> {
927927
);
928928

929929
let mut burst_size = 0;
930-
let left_before_size_switch = (self.code_buffer.max_code()
931-
- Code::from(self.is_tiff))
932-
.saturating_sub(self.next_code);
930+
let size_switch_at = self.code_buffer.max_code() - Code::from(self.is_tiff);
931+
// This is intended to wrap. As by the debug assert above, we keep the next
932+
// code bounded by the current size's max code where we switch code size.
933+
// Except in case the table is full then we actually want to allow decoding
934+
// of an arbitrary count of non-resetting symbols.
935+
let left_before_size_switch = size_switch_at.wrapping_sub(self.next_code);
933936

934937
// A burst is a sequence of decodes that are completely independent of each other. This
935938
// is the case if neither is an end code, a clear code, or a next code, i.e. we have

0 commit comments

Comments
 (0)