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
20 changes: 20 additions & 0 deletions src/compress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,18 @@ impl Compressor {
// We add 16 bytes margin for the last flush (8 bytes) and safety.
if bs.out_idx + 16 + (seq.litrunlen as usize * 2) < bs.output.len() {
let mut lit_remain = seq.litrunlen as usize;
while lit_remain >= 4 {
// SAFETY: We verified sufficient buffer space above.
// `write_literals_2` writes at most 30 bits and may flush 4 bytes.
// We do this twice, so max 60 bits + flush overhead.
// The loop precondition checks for space.
unsafe {
self.write_literals_2(bs, input[in_pos], input[in_pos + 1]);
self.write_literals_2(bs, input[in_pos + 2], input[in_pos + 3]);
}
in_pos += 4;
lit_remain -= 4;
}
while lit_remain >= 2 {
// SAFETY: We verified sufficient buffer space above.
// `write_literals_2` writes at most 30 bits and may flush 4 bytes.
Expand Down Expand Up @@ -1355,6 +1367,14 @@ impl Compressor {
if seq.litrunlen > 0 {
if bs.out_idx + 16 + (seq.litrunlen as usize * 2) < bs.output.len() {
let mut lit_remain = seq.litrunlen as usize;
while lit_remain >= 4 {
unsafe {
self.write_literals_2(bs, input[in_pos], input[in_pos + 1]);
self.write_literals_2(bs, input[in_pos + 2], input[in_pos + 3]);
}
in_pos += 4;
lit_remain -= 4;
}
while lit_remain >= 2 {
unsafe { self.write_literals_2(bs, input[in_pos], input[in_pos + 1]) };
in_pos += 2;
Expand Down