All the comparator API needs is > 0, < 0, or = 0 signalling: it does not
need +1, -1, 0. This avoids some useless branching.

This also adds const-correctness when needed for the comparators.

Signed-off-by: Ganesh Ajjanagadde <gajjanaga...@gmail.com>
---
 cmdutils_opencl.c               | 2 +-
 ffmpeg.c                        | 3 +--
 libavfilter/f_sendcmd.c         | 2 +-
 libavfilter/vf_removegrain.c    | 5 +----
 libavformat/subtitles.c         | 9 +++------
 libswresample/swresample-test.c | 6 +++---
 6 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/cmdutils_opencl.c b/cmdutils_opencl.c
index 61478e2..d9095b6 100644
--- a/cmdutils_opencl.c
+++ b/cmdutils_opencl.c
@@ -206,7 +206,7 @@ end:
 
 static int compare_ocl_device_desc(const void *a, const void *b)
 {
-    return ((OpenCLDeviceBenchmark*)a)->runtime - 
((OpenCLDeviceBenchmark*)b)->runtime;
+    return ((const OpenCLDeviceBenchmark*)a)->runtime - ((const 
OpenCLDeviceBenchmark*)b)->runtime;
 }
 
 int opt_opencl_bench(void *optctx, const char *opt, const char *arg)
diff --git a/ffmpeg.c b/ffmpeg.c
index a19c816..26c5ae9 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2578,8 +2578,7 @@ static InputStream *get_input_stream(OutputStream *ost)
 
 static int compare_int64(const void *a, const void *b)
 {
-    int64_t va = *(int64_t *)a, vb = *(int64_t *)b;
-    return va < vb ? -1 : va > vb ? +1 : 0;
+    return *(const int64_t *)a - *(const int64_t *)b;
 }
 
 static int init_output_stream(OutputStream *ost, char *error, int error_len)
diff --git a/libavfilter/f_sendcmd.c b/libavfilter/f_sendcmd.c
index 37aedc5..539be9c 100644
--- a/libavfilter/f_sendcmd.c
+++ b/libavfilter/f_sendcmd.c
@@ -367,7 +367,7 @@ static int cmp_intervals(const void *a, const void *b)
     int64_t ts_diff = i1->start_ts - i2->start_ts;
     int ret;
 
-    ret = ts_diff > 0 ? 1 : ts_diff < 0 ? -1 : 0;
+    ret = ts_diff;
     return ret == 0 ? i1->index - i2->index : ret;
 }
 
diff --git a/libavfilter/vf_removegrain.c b/libavfilter/vf_removegrain.c
index da17f6a..f675edd 100644
--- a/libavfilter/vf_removegrain.c
+++ b/libavfilter/vf_removegrain.c
@@ -82,10 +82,7 @@ static int mode01(int c, int a1, int a2, int a3, int a4, int 
a5, int a6, int a7,
 
 static int cmp_int(const void *p1, const void *p2)
 {
-    int left = *(const int *)p1;
-    int right = *(const int *)p2;
-
-    return ((left > right) - (left < right));
+    return *(const int *)p1 - *(const int *)p2;
 }
 
 static int mode02(int c, int a1, int a2, int a3, int a4, int a5, int a6, int 
a7, int a8)
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
index bb89766..1c1928b 100644
--- a/libavformat/subtitles.c
+++ b/libavformat/subtitles.c
@@ -146,12 +146,9 @@ static int cmp_pkt_sub_ts_pos(const void *a, const void *b)
 {
     const AVPacket *s1 = a;
     const AVPacket *s2 = b;
-    if (s1->pts == s2->pts) {
-        if (s1->pos == s2->pos)
-            return 0;
-        return s1->pos > s2->pos ? 1 : -1;
-    }
-    return s1->pts > s2->pts ? 1 : -1;
+    if (s1->pts == s2->pts)
+        return s1->pos - s2->pos;
+    return s1->pts - s2->pts;
 }
 
 static int cmp_pkt_sub_pos_ts(const void *a, const void *b)
diff --git a/libswresample/swresample-test.c b/libswresample/swresample-test.c
index 9caa750..0aa47c8 100644
--- a/libswresample/swresample-test.c
+++ b/libswresample/swresample-test.c
@@ -138,8 +138,8 @@ static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t 
*in, enum AVSampleForm
     }
 }
 
-static int cmp(const int *a, const int *b){
-    return *a - *b;
+static int cmp(const void *a, const void *b){
+    return *(const int *)a - *(const int *)b;
 }
 
 static void audiogen(void *data, enum AVSampleFormat sample_fmt,
@@ -271,7 +271,7 @@ int main(int argc, char **argv){
         r = (seed * (uint64_t)(max_tests - test)) >>32;
         FFSWAP(int, remaining_tests[r], remaining_tests[max_tests - test - 1]);
     }
-    qsort(remaining_tests + max_tests - num_tests, num_tests, 
sizeof(remaining_tests[0]), (void*)cmp);
+    qsort(remaining_tests + max_tests - num_tests, num_tests, 
sizeof(remaining_tests[0]), cmp);
     in_sample_rate=16000;
     for(test=0; test<num_tests; test++){
         char  in_layout_string[256];
-- 
2.6.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to