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 756292aa783aabd0449bfd76d61a20ade77dca85..18ab95c46d717bdd04a1c0db0557a1d5f90f405a 100644 |
--- a/webrtc/modules/audio_coding/neteq/audio_vector.h |
+++ b/webrtc/modules/audio_coding/neteq/audio_vector.h |
@@ -14,6 +14,7 @@ |
#include <string.h> // Access to size_t. |
#include <memory> |
+#include "webrtc/base/checks.h" |
#include "webrtc/base/constructormagic.h" |
#include "webrtc/typedefs.h" |
@@ -110,12 +111,30 @@ class AudioVector { |
virtual bool Empty() const; |
// Accesses and modifies an element of AudioVector. |
- const int16_t& operator[](size_t index) const; |
- int16_t& operator[](size_t index); |
+ inline const int16_t& operator[](size_t index) const { |
+ return array_[WrapIndex(index, begin_index_, capacity_)]; |
+ } |
+ |
+ inline int16_t& operator[](size_t index) { |
+ return array_[WrapIndex(index, begin_index_, capacity_)]; |
+ } |
private: |
static const size_t kDefaultInitialSize = 10; |
+ // This method is used by the [] operators to calculate an index within the |
+ // capacity of the array, but without using the modulo operation (%). |
+ 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 >= capacity |
+ ? begin_index + index - capacity |
+ : begin_index + index; |
+ RTC_DCHECK_LT(ix, capacity); |
+ return ix; |
+ } |
+ |
void Reserve(size_t n); |
void InsertByPushBack(const int16_t* insert_this, size_t length, |