diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-04-04 19:50:17 +0200 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-04-05 07:30:38 -0400 |
commit | 7000ccf89fd6b5f4bfb2fc67bd5ca1a6ad8e2c7a (patch) | |
tree | 8ce62be8304665bdcf744fe2602b33f2b0d2ebb9 | |
parent | b88c58b94ca028d12dbe453e1c1fa0e46f704b03 (diff) | |
download | serenity-7000ccf89fd6b5f4bfb2fc67bd5ca1a6ad8e2c7a.zip |
LibCompress: Copy LZMA repetitions from the buffer in sequence
This improves the decompression time of `clang-15.0.7.src.tar.xz` from
5.2 seconds down to about 2.7 seconds.
-rw-r--r-- | Userland/Libraries/LibCompress/Lzma.cpp | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/Userland/Libraries/LibCompress/Lzma.cpp b/Userland/Libraries/LibCompress/Lzma.cpp index 0ff8a38339..e2a160df88 100644 --- a/Userland/Libraries/LibCompress/Lzma.cpp +++ b/Userland/Libraries/LibCompress/Lzma.cpp @@ -520,22 +520,13 @@ ErrorOr<Bytes> LzmaDecompressor::read_some(Bytes bytes) if (m_options.uncompressed_size.has_value() && m_options.uncompressed_size.value() < m_total_decoded_bytes + real_length) return Error::from_string_literal("Tried to copy match beyond expected uncompressed file size"); - while (real_length > 0) { - if (m_dictionary->empty_space() == 0) { - m_leftover_match_length = real_length; - break; - } + auto copied_length = TRY(m_dictionary->copy_from_seekback(current_repetition_offset(), real_length)); - u8 byte; - auto read_bytes = TRY(m_dictionary->read_with_seekback({ &byte, sizeof(byte) }, current_repetition_offset())); - VERIFY(read_bytes.size() == sizeof(byte)); + m_total_decoded_bytes += copied_length; + real_length -= copied_length; - auto written_bytes = m_dictionary->write({ &byte, sizeof(byte) }); - VERIFY(written_bytes == sizeof(byte)); - m_total_decoded_bytes++; - - real_length--; - } + if (real_length > 0) + m_leftover_match_length = real_length; return {}; }; |