diff mbox series

[FFmpeg-devel,09/15] avutil/pixdesc: Use av_strstart where appropriate

Message ID 20210224115341.794293-9-andreas.rheinhardt@gmail.com
State Accepted
Commit 114603d0b9ce5440be5efce773361fb96c290b08
Headers show
Series [FFmpeg-devel,01/15] avformat/movenc: Remove always true check
Related show

Checks

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

Commit Message

Andreas Rheinhardt Feb. 24, 2021, 11:53 a.m. UTC
It makes the intent clearer and allows to avoid calculating the strlen
separately.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavutil/pixdesc.c | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 8274713226..2a919461a5 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -2702,11 +2702,13 @@  static int get_color_type(const AVPixFmtDescriptor *desc) {
     if(desc->nb_components == 1 || desc->nb_components == 2)
         return FF_COLOR_GRAY;
 
-    if(desc->name && !strncmp(desc->name, "yuvj", 4))
-        return FF_COLOR_YUV_JPEG;
+    if (desc->name) {
+        if (av_strstart(desc->name, "yuvj", NULL))
+            return FF_COLOR_YUV_JPEG;
 
-    if(desc->name && !strncmp(desc->name, "xyz", 3))
-        return FF_COLOR_XYZ;
+        if (av_strstart(desc->name, "xyz", NULL))
+            return FF_COLOR_XYZ;
+    }
 
     if(desc->flags & AV_PIX_FMT_FLAG_RGB)
         return  FF_COLOR_RGB;
@@ -2907,8 +2909,7 @@  int av_color_range_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_range_names); i++) {
-        size_t len = strlen(color_range_names[i]);
-        if (!strncmp(color_range_names[i], name, len))
+        if (av_strstart(name, color_range_names[i], NULL))
             return i;
     }
 
@@ -2926,13 +2927,10 @@  int av_color_primaries_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_primaries_names); i++) {
-        size_t len;
-
         if (!color_primaries_names[i])
             continue;
 
-        len = strlen(color_primaries_names[i]);
-        if (!strncmp(color_primaries_names[i], name, len))
+        if (av_strstart(name, color_primaries_names[i], NULL))
             return i;
     }
 
@@ -2950,13 +2948,10 @@  int av_color_transfer_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_transfer_names); i++) {
-        size_t len;
-
         if (!color_transfer_names[i])
             continue;
 
-        len = strlen(color_transfer_names[i]);
-        if (!strncmp(color_transfer_names[i], name, len))
+        if (av_strstart(name, color_transfer_names[i], NULL))
             return i;
     }
 
@@ -2974,13 +2969,10 @@  int av_color_space_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(color_space_names); i++) {
-        size_t len;
-
         if (!color_space_names[i])
             continue;
 
-        len = strlen(color_space_names[i]);
-        if (!strncmp(color_space_names[i], name, len))
+        if (av_strstart(name, color_space_names[i], NULL))
             return i;
     }
 
@@ -2998,13 +2990,10 @@  int av_chroma_location_from_name(const char *name)
     int i;
 
     for (i = 0; i < FF_ARRAY_ELEMS(chroma_location_names); i++) {
-        size_t len;
-
         if (!chroma_location_names[i])
             continue;
 
-        len = strlen(chroma_location_names[i]);
-        if (!strncmp(chroma_location_names[i], name, len))
+        if (av_strstart(name, chroma_location_names[i], NULL))
             return i;
     }