speedup q5-9 on large files

PiperOrigin-RevId: 553440457
This commit is contained in:
Evgenii Kliuchnikov 2023-08-03 04:58:16 -07:00 committed by Copybara-Service
parent 0b89871d86
commit a560089843

View File

@ -217,8 +217,12 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
const size_t down = const size_t down =
(num[key] > self->block_size_) ? (num[key] > self->block_size_) ?
(num[key] - self->block_size_) : 0u; (num[key] - self->block_size_) : 0u;
for (i = num[key]; i > down;) { const uint32_t first4 = BrotliUnalignedRead32(data + cur_ix_masked);
const size_t max_length_m4 = max_length - 4;
i = num[key];
for (; i > down;) {
size_t prev_ix = bucket[--i & self->block_mask_]; size_t prev_ix = bucket[--i & self->block_mask_];
uint32_t current4;
const size_t backward = cur_ix - prev_ix; const size_t backward = cur_ix - prev_ix;
if (BROTLI_PREDICT_FALSE(backward > max_backward)) { if (BROTLI_PREDICT_FALSE(backward > max_backward)) {
break; break;
@ -229,22 +233,19 @@ static BROTLI_INLINE void FN(FindLongestMatch)(
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) { data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue; continue;
} }
current4 = BrotliUnalignedRead32(data + prev_ix);
if (first4 != current4) continue;
{ {
const size_t len = FindMatchLengthWithLimit(&data[prev_ix], const size_t len = FindMatchLengthWithLimit(&data[prev_ix + 4],
&data[cur_ix_masked], &data[cur_ix_masked + 4],
max_length); max_length_m4) + 4;
if (len >= 4) { const score_t score = BackwardReferenceScore(len, backward);
/* Comparing for >= 3 does not change the semantics, but just saves if (best_score < score) {
for a few unnecessary binary logarithms in backward reference best_score = score;
score, since we are not interested in such short matches. */ best_len = len;
score_t score = BackwardReferenceScore(len, backward); out->len = best_len;
if (best_score < score) { out->distance = backward;
best_score = score; out->score = best_score;
best_len = len;
out->len = best_len;
out->distance = backward;
out->score = best_score;
}
} }
} }
} }