Hoist the static bounds check out of the combined if check.

PiperOrigin-RevId: 639054702
This commit is contained in:
Brotli 2024-05-31 09:10:52 -07:00 committed by Copybara-Service
parent fe754f3459
commit a528bce9f6
4 changed files with 32 additions and 16 deletions

View File

@ -192,8 +192,10 @@ 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 (cur_ix_masked + best_len > ring_buffer_mask) {
break;
}
if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@ -239,8 +241,10 @@ 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 (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 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {

View File

@ -209,8 +209,10 @@ 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 (cur_ix_masked + best_len > ring_buffer_mask) {
break;
}
if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@ -263,8 +265,10 @@ 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 (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 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {

View File

@ -192,8 +192,10 @@ 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 (cur_ix_masked + best_len > ring_buffer_mask) {
break;
}
if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@ -234,8 +236,10 @@ 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 (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 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {

View File

@ -184,8 +184,10 @@ 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 (cur_ix_masked + best_len > ring_buffer_mask) {
break;
}
if (prev_ix + best_len > ring_buffer_mask ||
data[cur_ix_masked + best_len] != data[prev_ix + best_len]) {
continue;
}
@ -235,8 +237,10 @@ 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 (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 */
BrotliUnalignedRead32(&data[cur_ix_masked + best_len - 3]) !=
BrotliUnalignedRead32(&data[prev_ix + best_len - 3])) {