Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: webrtc/modules/audio_coding/neteq/audio_vector.h

Issue 2706263002: Improved readability and DCHECKing in AudioVector::[] (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/audio_coding/neteq/audio_vector.h
diff --git a/webrtc/modules/audio_coding/neteq/audio_vector.h b/webrtc/modules/audio_coding/neteq/audio_vector.h
index 9100ff896893ebd43e53b7dbb4cfede2f10b48e5..57e01ab2e1290b64f2df40c3e7ac473690fb5cd5 100644
--- a/webrtc/modules/audio_coding/neteq/audio_vector.h
+++ b/webrtc/modules/audio_coding/neteq/audio_vector.h
@@ -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.
nisse-webrtc 2017/02/22 07:48:40 Given above DCHECKS, this could fail only if capac
kwiberg-webrtc 2017/02/22 08:25:48 Aha. The two DCHECKs on line 130 and 131 guarantee
+ if (ix >= capacity) {
+ ix -= capacity;
+ }
RTC_DCHECK_LT(ix, capacity);
return ix;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698