mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:17:35 +00:00
LibCompress: Simplify logic in deflate implementation.
This commit is contained in:
parent
6de63782c7
commit
4c317a94c7
2 changed files with 36 additions and 9 deletions
|
@ -138,17 +138,18 @@ bool DeflateDecompressor::CompressedBlock::try_read_more()
|
|||
m_eof = true;
|
||||
return false;
|
||||
} else {
|
||||
// FIXME: This assertion depends on user input.
|
||||
ASSERT(m_distance_codes.has_value());
|
||||
if (!m_distance_codes.has_value()) {
|
||||
m_decompressor.set_fatal_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto run_length = m_decompressor.decode_run_length(symbol);
|
||||
const auto distance = m_decompressor.decode_distance(m_distance_codes.value().read_symbol(m_decompressor.m_input_stream));
|
||||
|
||||
size_t nread = 0;
|
||||
while (nread < run_length) {
|
||||
const auto nreserved = min(run_length - nread, m_decompressor.m_output_stream.remaining_contigous_space());
|
||||
auto bytes = m_decompressor.m_output_stream.reserve_contigous_space(nreserved);
|
||||
nread += m_decompressor.m_output_stream.read(bytes, distance + nread + nreserved);
|
||||
for (size_t idx = 0; idx < run_length; ++idx) {
|
||||
u8 byte = 0;
|
||||
m_decompressor.m_output_stream.read({ &byte, sizeof(byte) }, distance);
|
||||
m_decompressor.m_output_stream << byte;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue