OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 117 |
118 inline int16_t& operator[](size_t index) { | 118 inline int16_t& operator[](size_t index) { |
119 return array_[WrapIndex(index, begin_index_, capacity_)]; | 119 return array_[WrapIndex(index, begin_index_, capacity_)]; |
120 } | 120 } |
121 | 121 |
122 private: | 122 private: |
123 static const size_t kDefaultInitialSize = 10; | 123 static const size_t kDefaultInitialSize = 10; |
124 | 124 |
125 // This method is used by the [] operators to calculate an index within the | 125 // This method is used by the [] operators to calculate an index within the |
126 // capacity of the array, but without using the modulo operation (%). | 126 // capacity of the array, but without using the modulo operation (%). |
127 static inline size_t WrapIndex(size_t index, | 127 static inline size_t WrapIndex(size_t index, |
nisse-webrtc
2017/02/17 08:28:26
This is going to work correctly only when index an
kwiberg-webrtc
2017/02/17 09:43:23
We already DCHECK that ix got a reasonable value b
| |
128 size_t begin_index, | 128 size_t begin_index, |
129 size_t capacity) { | 129 size_t capacity) { |
130 RTC_DCHECK_GE(begin_index + index, index); // Check for overflow. | 130 RTC_DCHECK_GE(begin_index + index, index); // Check for overflow. |
131 const size_t ix = begin_index + index >= capacity | 131 const size_t ix = |
132 ? begin_index + index - capacity | 132 begin_index + index - (begin_index + index >= capacity ? capacity : 0); |
nisse-webrtc
2017/02/17 08:28:25
I'm guess the compiler can recognize (begin_index
kwiberg-webrtc
2017/02/17 09:43:23
Yes, I agree that is more readable. I don't like m
| |
133 : begin_index + index; | |
134 RTC_DCHECK_LT(ix, capacity); | 133 RTC_DCHECK_LT(ix, capacity); |
135 return ix; | 134 return ix; |
136 } | 135 } |
137 | 136 |
138 void Reserve(size_t n); | 137 void Reserve(size_t n); |
139 | 138 |
140 void InsertByPushBack(const int16_t* insert_this, size_t length, | 139 void InsertByPushBack(const int16_t* insert_this, size_t length, |
141 size_t position); | 140 size_t position); |
142 | 141 |
143 void InsertByPushFront(const int16_t* insert_this, size_t length, | 142 void InsertByPushFront(const int16_t* insert_this, size_t length, |
(...skipping 12 matching lines...) Expand all Loading... | |
156 size_t begin_index_; | 155 size_t begin_index_; |
157 | 156 |
158 // The index of the sample after the last sample in |array_|. | 157 // The index of the sample after the last sample in |array_|. |
159 size_t end_index_; | 158 size_t end_index_; |
160 | 159 |
161 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); | 160 RTC_DISALLOW_COPY_AND_ASSIGN(AudioVector); |
162 }; | 161 }; |
163 | 162 |
164 } // namespace webrtc | 163 } // namespace webrtc |
165 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ | 164 #endif // WEBRTC_MODULES_AUDIO_CODING_NETEQ_AUDIO_VECTOR_H_ |
OLD | NEW |