1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

AK: Split up CircularBuffer::find_copy_in_seekback

The "operation modes" of this function have very different focuses, and
trying to combine both in a way where we share the most amount of code
probably results in the worst performance.

Instead, split up the function into "existing distances" and "no
existing distances" so that we can optimize either case separately.
This commit is contained in:
Tim Schumacher 2023-06-01 22:24:28 +02:00 committed by Linus Groh
parent 9e82ad758e
commit 046a9faeb3
4 changed files with 91 additions and 53 deletions

View file

@ -992,13 +992,13 @@ ErrorOr<void> LzmaCompressor::encode_match_type(MatchType match_type)
ErrorOr<void> LzmaCompressor::encode_once()
{
// Check if any of our existing match distances are currently usable.
Vector<size_t> const existing_distance_hints {
Vector<size_t> const existing_distances {
m_rep0 + normalized_to_real_match_distance_offset,
m_rep1 + normalized_to_real_match_distance_offset,
m_rep2 + normalized_to_real_match_distance_offset,
m_rep3 + normalized_to_real_match_distance_offset,
};
auto existing_distance_results = TRY(m_dictionary->find_copy_in_seekback(m_dictionary->used_space(), normalized_to_real_match_length_offset, existing_distance_hints));
auto existing_distance_results = TRY(m_dictionary->find_copy_in_seekback(existing_distances, m_dictionary->used_space(), normalized_to_real_match_length_offset));
if (existing_distance_results.size() > 0) {
auto selected_match = existing_distance_results[0];