diff mbox series

[FFmpeg-devel,5/5] avfilter/signature_lookup: Avoid branch when adding to linked list

Message ID AS8P250MB074407A36091A0BCBC1BD2868F4E2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit cc36a9f5b93557aeb391568641998b18961621e0
Headers show
Series [FFmpeg-devel,1/5] avfilter/vf_signature: Allocate arrays together | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 14, 2024, 12:05 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/signature_lookup.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c
index ff0d23c5c7..9c69c02fbf 100644
--- a/libavfilter/signature_lookup.c
+++ b/libavfilter/signature_lookup.c
@@ -187,7 +187,7 @@  static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont
     size_t i, j, k, l, hmax = 0, score;
     int framerate, offset, l1dist;
     double m;
-    MatchingInfo *cands = NULL, *c = NULL;
+    MatchingInfo cands = { 0 }, *c = &cands;
 
     struct {
         uint8_t size;
@@ -295,16 +295,10 @@  static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont
         for (i = 0; i < MAX_FRAMERATE; i++) {
             for (j = 0; j < HOUGH_MAX_OFFSET; j++) {
                 if (hmax < hspace[i][j].score) {
-                    if (c == NULL) {
-                        c = av_malloc(sizeof(MatchingInfo));
-                        cands = c;
-                    } else {
-                        c->next = av_malloc(sizeof(MatchingInfo));
-                        c = c->next;
-
-                    }
+                    c->next = av_malloc(sizeof(MatchingInfo));
+                    c = c->next;
                     if (!c) {
-                        sll_free(&cands);
+                        sll_free(&cands.next);
                         goto error;
                     }
                     c->framerateratio = (i+1.0) / 30;
@@ -325,7 +319,7 @@  static MatchingInfo* get_matching_parameters(AVFilterContext *ctx, SignatureCont
     error:
     av_freep(&hspace);
     av_free(hspaces);
-    return cands;
+    return cands.next;
 }
 
 static int iterate_frame(double frr, FineSignature **a, FineSignature **b, int fcount, int *bcount, int dir)