diff options
Diffstat (limited to 'c/enc/hash_longest_match_inc.h')
-rw-r--r-- | c/enc/hash_longest_match_inc.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/c/enc/hash_longest_match_inc.h b/c/enc/hash_longest_match_inc.h index 788e9ef..608fa66 100644 --- a/c/enc/hash_longest_match_inc.h +++ b/c/enc/hash_longest_match_inc.h @@ -208,6 +208,11 @@ static BROTLI_INLINE void FN(FindLongestMatch)( } } } + /* we require matches of len >4, so increase best_len to 3, so we can compare + * 4 bytes all the time. */ + if (best_len < 3) { + best_len = 3; + } { const uint32_t key = FN(HashBytes)(&data[cur_ix_masked], self->hash_shift_); @@ -223,7 +228,9 @@ static BROTLI_INLINE void FN(FindLongestMatch)( prev_ix &= ring_buffer_mask; if (cur_ix_masked + best_len > ring_buffer_mask || prev_ix + best_len > ring_buffer_mask || - data[cur_ix_masked + best_len] != data[prev_ix + best_len]) { + /* compare 4 bytes ending at best_len + 1 */ + BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) != + BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) { continue; } { |