[FFmpeg-devel] [PATCH 3/3] avutil/dict: Avoid check whose result is known in advance

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Sep 13 22:46:28 EEST 2022


We know that an AVDictionary is not empty if we have just added
an entry to it, so only check for it being empty on the branch
that does not do so.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavutil/dict.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavutil/dict.c b/libavutil/dict.c
index 1968063b0b..4bba041d0a 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value,
         m->elems[m->count].value = copy_value;
         m->count++;
     } else {
+        if (!m->count) {
+            av_freep(&m->elems);
+            av_freep(pm);
+        }
         av_freep(&copy_key);
     }
-    if (!m->count) {
-        av_freep(&m->elems);
-        av_freep(pm);
-    }
 
     return 0;
 
-- 
2.34.1



More information about the ffmpeg-devel mailing list