Remove unnecessary ring buffer boundary checks. PiperOrigin-RevId: 990982480
diff --git a/c/enc/hash.h b/c/enc/hash.h index 35addc8..0340611 100644 --- a/c/enc/hash.h +++ b/c/enc/hash.h
@@ -850,8 +850,6 @@ } #endif - BROTLI_DCHECK(cur_ix_masked + max_length <= ring_buffer_mask + 1); - for (i = 0; i < 4; ++i) { const size_t distance = (size_t)distance_cache[i]; size_t offset; @@ -895,7 +893,7 @@ limit = source_size - offset; limit = (limit > max_length) ? max_length : limit; if (distance > max_distance) continue; - if (cur_ix_masked + best_len > ring_buffer_mask || best_len >= limit || + if (best_len >= limit || /* compare 4 bytes ending at best_len + 1 */ BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) != BrotliUnalignedRead32(&source[offset + best_len - 3])) {
diff --git a/c/enc/hash_longest_match_simd_opt_inc.h b/c/enc/hash_longest_match_simd_opt_inc.h index 6985a5d..6c54fae 100644 --- a/c/enc/hash_longest_match_simd_opt_inc.h +++ b/c/enc/hash_longest_match_simd_opt_inc.h
@@ -190,11 +190,7 @@ } prev_ix &= ring_buffer_mask; - if (cur_ix_masked + best_len > ring_buffer_mask) { - break; - } - if (prev_ix + best_len > ring_buffer_mask || - BrotliUnalignedRead16(&data[cur_ix_masked + best_len - 1]) != + if (BrotliUnalignedRead16(&data[cur_ix_masked + best_len - 1]) != BrotliUnalignedRead16(&data[prev_ix + best_len - 1])) { continue; } @@ -244,11 +240,7 @@ break; } prev_ix &= ring_buffer_mask; - if (cur_ix_masked + best_len > ring_buffer_mask) { - break; - } - if (prev_ix + best_len > ring_buffer_mask || - /* compare 4 bytes ending at best_len + 1 */ + if (/* compare 4 bytes ending at best_len + 1 */ BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) != BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) { continue;