From dffef6bb71bf1012868ad0cd80fbe671375d265c Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Thu, 20 Apr 2023 21:41:14 +0200 Subject: [PATCH] LibCompress: Remove special casing for looping DEFLATE seekbacks The `copy_from_seekback` method already handles this exactly as DEFLATE expects, but it is slightly more optimized. --- Userland/Libraries/LibCompress/Deflate.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index bdb7135f3e1..1eb391594bb 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -211,18 +211,10 @@ ErrorOr DeflateDecompressor::CompressedBlock::try_read_more() auto const distance = TRY(m_decompressor.decode_distance(distance_symbol)); - if (distance < length) { - for (size_t idx = 0; idx < length; ++idx) { - u8 byte = 0; - TRY(m_decompressor.m_output_buffer.read_with_seekback({ &byte, sizeof(byte) }, distance)); - m_decompressor.m_output_buffer.write({ &byte, sizeof(byte) }); - } - } else { - auto copied_length = TRY(m_decompressor.m_output_buffer.copy_from_seekback(distance, length)); + auto copied_length = TRY(m_decompressor.m_output_buffer.copy_from_seekback(distance, length)); - // TODO: What should we do if the output buffer is full? - VERIFY(copied_length == length); - } + // TODO: What should we do if the output buffer is full? + VERIFY(copied_length == length); return true; }