diff options
author | Brotli <no-reply@google.com> | 2024-04-12 06:50:04 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-12 06:50:51 -0700 |
commit | a76d96e7308614b422508679d6905cbe1a8762bf (patch) | |
tree | d1c80487b83392410db20c995e53847c862a939a /c/enc/hash_longest_match64_inc.h | |
parent | a813a6a1e43650f6ee5ab590051a218bcb958352 (diff) | |
download | brotli-a76d96e7308614b422508679d6905cbe1a8762bf.zip brotli-a76d96e7308614b422508679d6905cbe1a8762bf.tar.gz brotli-a76d96e7308614b422508679d6905cbe1a8762bf.tar.bz2 |
Don't check `cur_ix_masked` against `ring_buffer_mask`.
`cur_ix_masked` isn't changing from iteration to iteration, and `max_length` ensures we never find a match long enough to walk off the ring buffer.
PiperOrigin-RevId: 624162764
Diffstat (limited to 'c/enc/hash_longest_match64_inc.h')
-rw-r--r-- | c/enc/hash_longest_match64_inc.h | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/c/enc/hash_longest_match64_inc.h b/c/enc/hash_longest_match64_inc.h index 8f825de..9834c2a 100644 --- a/c/enc/hash_longest_match64_inc.h +++ b/c/enc/hash_longest_match64_inc.h @@ -165,6 +165,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)( uint16_t* BROTLI_RESTRICT num = self->num_; uint32_t* BROTLI_RESTRICT buckets = self->buckets_; const size_t cur_ix_masked = cur_ix & ring_buffer_mask; + BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask) /* Don't accept a short copy from far away. */ score_t min_score = out->score; score_t best_score = out->score; @@ -184,8 +185,7 @@ 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 || + if (prev_ix + best_len > ring_buffer_mask || data[cur_ix_masked + best_len] != data[prev_ix + best_len]) { continue; } @@ -233,8 +233,7 @@ static BROTLI_INLINE void FN(FindLongestMatch)( break; } prev_ix &= ring_buffer_mask; - if (cur_ix_masked + best_len > ring_buffer_mask || - prev_ix + best_len > ring_buffer_mask || + if (prev_ix + best_len > ring_buffer_mask || /* compare 4 bytes ending at best_len + 1 */ BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) != BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) { |