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

Unified Diff: webrtc/common_audio/signal_processing/min_max_operations.c

Issue 1305983003: Convert some more things to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Support Android's C89 mode Created 5 years, 4 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
Index: webrtc/common_audio/signal_processing/min_max_operations.c
diff --git a/webrtc/common_audio/signal_processing/min_max_operations.c b/webrtc/common_audio/signal_processing/min_max_operations.c
index 22ce765455ba0f39dead6a523a1ec43bade5df63..4a962f86a031475b9c98b24af86c6c645912a775 100644
--- a/webrtc/common_audio/signal_processing/min_max_operations.c
+++ b/webrtc/common_audio/signal_processing/min_max_operations.c
@@ -24,10 +24,11 @@
*
*/
-#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
-
+#include <assert.h>
#include <stdlib.h>
+#include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
+
// TODO(bjorn/kma): Consolidate function pairs (e.g. combine
// WebRtcSpl_MaxAbsValueW16C and WebRtcSpl_MaxAbsIndexW16 into a single one.)
// TODO(kma): Move the next six functions into min_max_operations_c.c.
@@ -37,9 +38,7 @@ int16_t WebRtcSpl_MaxAbsValueW16C(const int16_t* vector, size_t length) {
size_t i = 0;
int absolute = 0, maximum = 0;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -65,9 +64,7 @@ int32_t WebRtcSpl_MaxAbsValueW32C(const int32_t* vector, size_t length) {
uint32_t absolute = 0, maximum = 0;
size_t i = 0;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -86,9 +83,7 @@ int16_t WebRtcSpl_MaxValueW16C(const int16_t* vector, size_t length) {
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
size_t i = 0;
- if (vector == NULL || length == 0) {
- return maximum;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum)
@@ -102,9 +97,7 @@ int32_t WebRtcSpl_MaxValueW32C(const int32_t* vector, size_t length) {
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
size_t i = 0;
- if (vector == NULL || length == 0) {
- return maximum;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum)
@@ -118,9 +111,7 @@ int16_t WebRtcSpl_MinValueW16C(const int16_t* vector, size_t length) {
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
size_t i = 0;
- if (vector == NULL || length == 0) {
- return minimum;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum)
@@ -134,9 +125,7 @@ int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
size_t i = 0;
- if (vector == NULL || length == 0) {
- return minimum;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum)
@@ -146,15 +135,13 @@ int32_t WebRtcSpl_MinValueW32C(const int32_t* vector, size_t length) {
}
// Index of maximum absolute value in a word16 vector.
-int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
+size_t WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
// Use type int for local variables, to accomodate the value of abs(-32768).
size_t i = 0, index = 0;
int absolute = 0, maximum = 0;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
absolute = abs((int)vector[i]);
@@ -165,17 +152,15 @@ int WebRtcSpl_MaxAbsIndexW16(const int16_t* vector, size_t length) {
}
}
- return (int)index;
+ return index;
}
// Index of maximum value in a word16 vector.
-int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
+size_t WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
size_t i = 0, index = 0;
int16_t maximum = WEBRTC_SPL_WORD16_MIN;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum) {
@@ -184,17 +169,15 @@ int WebRtcSpl_MaxIndexW16(const int16_t* vector, size_t length) {
}
}
- return (int)index;
+ return index;
}
// Index of maximum value in a word32 vector.
-int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
+size_t WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
size_t i = 0, index = 0;
int32_t maximum = WEBRTC_SPL_WORD32_MIN;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] > maximum) {
@@ -203,17 +186,15 @@ int WebRtcSpl_MaxIndexW32(const int32_t* vector, size_t length) {
}
}
- return (int)index;
+ return index;
}
// Index of minimum value in a word16 vector.
-int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
+size_t WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
size_t i = 0, index = 0;
int16_t minimum = WEBRTC_SPL_WORD16_MAX;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum) {
@@ -222,17 +203,15 @@ int WebRtcSpl_MinIndexW16(const int16_t* vector, size_t length) {
}
}
- return (int)index;
+ return index;
}
// Index of minimum value in a word32 vector.
-int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
+size_t WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
size_t i = 0, index = 0;
int32_t minimum = WEBRTC_SPL_WORD32_MAX;
- if (vector == NULL || length == 0) {
- return -1;
- }
+ assert(length > 0);
for (i = 0; i < length; i++) {
if (vector[i] < minimum) {
@@ -241,5 +220,5 @@ int WebRtcSpl_MinIndexW32(const int32_t* vector, size_t length) {
}
}
- return (int)index;
+ return index;
}

Powered by Google App Engine
This is Rietveld 408576698