diff mbox series

[FFmpeg-devel,04/11] avcodec/movtextdec: Simplify finding default font

Message ID 20201017182248.577108-4-andreas.rheinhardt@gmail.com
State Accepted
Commit c33b9fa74b6f167f472bd26e6ffa3cb796084c77
Headers show
Series [FFmpeg-devel,01/11] avcodec/movtextdec: Reset counter of fonts when freeing them
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 17, 2020, 6:22 p.m. UTC
There is no need to walk through the list of fonts twice.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/movtextdec.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index e46c932c20..974118c4c1 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -145,7 +145,7 @@  static void mov_text_cleanup_ftab(MovTextContext *m)
 static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
 {
     uint8_t *tx3g_ptr = avctx->extradata;
-    int i, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL;
+    int i, j = -1, font_length, remaining = avctx->extradata_size - BOX_SIZE_INITIAL;
     int8_t v_align, h_align;
     unsigned ftab_entries;
     StyleBox s_default;
@@ -230,6 +230,8 @@  static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
 
     for (i = 0; i < m->ftab_entries; i++) {
         m->ftab[i].fontID = AV_RB16(tx3g_ptr);
+        if (m->ftab[i].fontID == m->d.fontID)
+            j = i;
         tx3g_ptr += 2;
         font_length = *tx3g_ptr++;
 
@@ -247,10 +249,8 @@  static int mov_text_tx3g(AVCodecContext *avctx, MovTextContext *m)
         m->ftab[i].font[font_length] = '\0';
         tx3g_ptr = tx3g_ptr + font_length;
     }
-    for (i = 0; i < m->ftab_entries; i++) {
-        if (m->d.fontID == m->ftab[i].fontID)
-            m->d.font = m->ftab[i].font;
-    }
+    if (j >= 0)
+        m->d.font = m->ftab[j].font;
     return 0;
 }