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

Unified Diff: webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.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/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
diff --git a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
index b6cc2406831952e7395b1cdb8d102318a2963da9..2b58abc4f94c74cbf22ee9426918c6dee561828e 100644
--- a/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
+++ b/webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.c
@@ -18,29 +18,18 @@
#include "defines.h"
-/*----------------------------------------------------------------*
- * Find index in array such that the array element with said
- * index is the element of said array closest to "value"
- * according to the squared-error criterion
- *---------------------------------------------------------------*/
-
-void WebRtcIlbcfix_NearestNeighbor(
- int16_t *index, /* (o) index of array element closest to value */
- int16_t *array, /* (i) data array (Q2) */
- int16_t value, /* (i) value (Q2) */
- size_t arlength /* (i) dimension of data array (==8) */
- ){
+void WebRtcIlbcfix_NearestNeighbor(size_t* index,
+ const size_t* array,
+ size_t value,
+ size_t arlength) {
size_t i;
- int16_t diff;
- /* Stack based */
- int32_t crit[8];
-
- /* Calculate square distance */
- for(i=0;i<arlength;i++){
- diff=array[i]-value;
- crit[i] = diff * diff;
+ size_t min_diff = (size_t)-1;
+ for (i = 0; i < arlength; i++) {
+ const size_t diff =
+ (array[i] < value) ? (value - array[i]) : (array[i] - value);
+ if (diff < min_diff) {
+ *index = i;
+ min_diff = diff;
+ }
}
-
- /* Find the minimum square distance */
- *index=WebRtcSpl_MinIndexW32(crit, arlength);
}
« no previous file with comments | « webrtc/modules/audio_coding/codecs/ilbc/nearest_neighbor.h ('k') | webrtc/modules/audio_coding/codecs/ilbc/refiner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698