AGC2 RNN VAD size_t -> int
Motivation: read "On Unsigned Integers" section in
https://google.github.io/styleguide/cppguide.html#Integer_Types
Plus, improved readability by getting rid of a bunch of
`static_cast<int>`s.
Bug: webrtc:10480
Change-Id: I911aa8cd08f5ccde4ee6f23534240d1faa84cdea
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190880
Commit-Queue: Alessio Bazzica <alessiob@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32524}
diff --git a/modules/audio_processing/agc2/rnn_vad/symmetric_matrix_buffer.h b/modules/audio_processing/agc2/rnn_vad/symmetric_matrix_buffer.h
index f0282aa..dd3b62a 100644
--- a/modules/audio_processing/agc2/rnn_vad/symmetric_matrix_buffer.h
+++ b/modules/audio_processing/agc2/rnn_vad/symmetric_matrix_buffer.h
@@ -18,6 +18,7 @@
#include "api/array_view.h"
#include "rtc_base/checks.h"
+#include "rtc_base/numerics/safe_compare.h"
namespace webrtc {
namespace rnn_vad {
@@ -29,7 +30,7 @@
// removed when one of the two corresponding items that have been compared is
// removed from the ring buffer. It is assumed that the comparison is symmetric
// and that comparing an item with itself is not needed.
-template <typename T, size_t S>
+template <typename T, int S>
class SymmetricMatrixBuffer {
static_assert(S > 2, "");
@@ -55,9 +56,9 @@
// column left.
std::memmove(buf_.data(), buf_.data() + S, (buf_.size() - S) * sizeof(T));
// Copy new values in the last column in the right order.
- for (size_t i = 0; i < values.size(); ++i) {
- const size_t index = (S - 1 - i) * (S - 1) - 1;
- RTC_DCHECK_LE(static_cast<size_t>(0), index);
+ for (int i = 0; rtc::SafeLt(i, values.size()); ++i) {
+ const int index = (S - 1 - i) * (S - 1) - 1;
+ RTC_DCHECK_GE(index, 0);
RTC_DCHECK_LT(index, buf_.size());
buf_[index] = values[i];
}
@@ -65,9 +66,9 @@
// Reads the value that corresponds to comparison of two items in the ring
// buffer having delay |delay1| and |delay2|. The two arguments must not be
// equal and both must be in {0, ..., S - 1}.
- T GetValue(size_t delay1, size_t delay2) const {
- int row = S - 1 - static_cast<int>(delay1);
- int col = S - 1 - static_cast<int>(delay2);
+ T GetValue(int delay1, int delay2) const {
+ int row = S - 1 - delay1;
+ int col = S - 1 - delay2;
RTC_DCHECK_NE(row, col) << "The diagonal cannot be accessed.";
if (row > col)
std::swap(row, col); // Swap to access the upper-right triangular part.