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

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

Issue 2670643007: Make AudioVector::operator[] inline and modify index calculation (Closed)
Patch Set: Review comments 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 | webrtc/modules/audio_coding/neteq/audio_vector.cc » ('j') | 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 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,
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/neteq/audio_vector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698