Improved readability and DCHECKing in AudioVector::[]

This is a follow-up to https://codereview.webrtc.org/2700633003, where
post-commit comments suggested these changes.

BUG=webrtc:7159

Review-Url: https://codereview.webrtc.org/2706263002
Cr-Commit-Position: refs/heads/master@{#16771}
This commit is contained in:
henrik.lundin
2017-02-22 03:45:40 -08:00
committed by Commit bot
parent a14d16ea7d
commit 5650a7d1c4

View File

@ -127,9 +127,13 @@ class AudioVector {
static inline size_t WrapIndex(size_t index,
size_t begin_index,
size_t capacity) {
RTC_DCHECK_GE(begin_index + index, index); // Check for overflow.
const size_t ix =
begin_index + index - (begin_index + index >= capacity ? capacity : 0);
RTC_DCHECK_LT(index, capacity);
RTC_DCHECK_LT(begin_index, capacity);
size_t ix = begin_index + index;
RTC_DCHECK_GE(ix, index); // Check for overflow.
if (ix >= capacity) {
ix -= capacity;
}
RTC_DCHECK_LT(ix, capacity);
return ix;
}