diff mbox series

[FFmpeg-devel,v2,2/5] avutil/dict: Use av_dict_iterate in av_dict_get

Message ID 20220924143659.74756-2-epirat07@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v2,1/5] avutil/dict: Add av_dict_iterate | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marvin Scholz Sept. 24, 2022, 2:36 p.m. UTC
---
 libavutil/dict.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Anton Khirnov Oct. 25, 2022, 9:46 a.m. UTC | #1
Quoting Marvin Scholz (2022-09-24 16:36:56)
> ---
>  libavutil/dict.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/libavutil/dict.c b/libavutil/dict.c
> index ee059d712c..ea03590d0f 100644
> --- a/libavutil/dict.c
> +++ b/libavutil/dict.c
> @@ -60,18 +60,14 @@ const AVDictionaryEntry *av_dict_iterate(const AVDictionary *m,
>  AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
>                                 const AVDictionaryEntry *prev, int flags)
>  {
> -    unsigned int i, j;
> +   const AVDictionaryEntry *entry = prev;

Broken indentation, otherwise looks good.
diff mbox series

Patch

diff --git a/libavutil/dict.c b/libavutil/dict.c
index ee059d712c..ea03590d0f 100644
--- a/libavutil/dict.c
+++ b/libavutil/dict.c
@@ -60,18 +60,14 @@  const AVDictionaryEntry *av_dict_iterate(const AVDictionary *m,
 AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
                                const AVDictionaryEntry *prev, int flags)
 {
-    unsigned int i, j;
+   const AVDictionaryEntry *entry = prev;
+    unsigned int j;
 
-    if (!m || !key)
+    if (!key)
         return NULL;
 
-    if (prev)
-        i = prev - m->elems + 1;
-    else
-        i = 0;
-
-    for (; i < m->count; i++) {
-        const char *s = m->elems[i].key;
+    while ((entry = av_dict_iterate(m, entry))) {
+        const char *s = entry->key;
         if (flags & AV_DICT_MATCH_CASE)
             for (j = 0; s[j] == key[j] && key[j]; j++)
                 ;
@@ -82,7 +78,7 @@  AVDictionaryEntry *av_dict_get(const AVDictionary *m, const char *key,
             continue;
         if (s[j] && !(flags & AV_DICT_IGNORE_SUFFIX))
             continue;
-        return &m->elems[i];
+        return (AVDictionaryEntry *)entry;
     }
     return NULL;
 }