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

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

Issue 2670643007: Make AudioVector::operator[] inline and modify index calculation (Closed)
Patch Set: Rewrite index calculation 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..e52c5a14d1ff746b0c6c4f9b540a17e835c5052c 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,8 +111,21 @@ 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 {
kwiberg-webrtc 2017/02/13 14:44:08 You should also DCHECK that begin_index_ + index d
hlundin-webrtc 2017/02/14 08:49:28 Done.
+ const size_t ix = begin_index_ + index >= capacity_ ?
+ begin_index_ + index - capacity_ :
+ begin_index_ + index;
+ RTC_DCHECK_LT(ix, capacity_);
+ return array_[ix];
+ }
+
+ inline int16_t& operator[](size_t index) {
+ const size_t ix = begin_index_ + index >= capacity_ ?
+ begin_index_ + index - capacity_ :
+ begin_index_ + index;
+ RTC_DCHECK_LT(ix, capacity_);
kwiberg-webrtc 2017/02/13 14:44:08 Break out the index calculation to a separate func
hlundin-webrtc 2017/02/14 08:49:28 Done.
+ return array_[ix];
+ }
private:
static const size_t kDefaultInitialSize = 10;
« 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