[x264-devel] y4m: Avoid some redundant strlen() calls

Henrik Gramner git at videolan.org
Sun Jan 17 22:17:55 CET 2016


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Mon Oct 26 18:52:46 2015 +0100| [8b2d2a6d51abf51ad38dd8705d280448fbe63aaf] | committer: Henrik Gramner

y4m: Avoid some redundant strlen() calls

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=8b2d2a6d51abf51ad38dd8705d280448fbe63aaf
---

 input/y4m.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/input/y4m.c b/input/y4m.c
index f32cc9b..130ea37 100644
--- a/input/y4m.c
+++ b/input/y4m.c
@@ -85,7 +85,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     if( h->fh == NULL )
         return -1;
 
-    h->frame_header_len = strlen( Y4M_FRAME_MAGIC )+1;
+    h->frame_header_len = sizeof(Y4M_FRAME_MAGIC);
 
     /* Read header */
     for( i = 0; i < MAX_YUV4_HEADER; i++ )
@@ -100,13 +100,13 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
             break;
         }
     }
-    if( i == MAX_YUV4_HEADER || strncmp( header, Y4M_MAGIC, strlen( Y4M_MAGIC ) ) )
+    if( i == MAX_YUV4_HEADER || strncmp( header, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1 ) )
         return -1;
 
     /* Scan properties */
     header_end = &header[i+1]; /* Include space */
     h->seq_header_len = i+1;
-    for( char *tokstart = &header[strlen( Y4M_MAGIC )+1]; tokstart < header_end; tokstart++ )
+    for( char *tokstart = header + sizeof(Y4M_MAGIC); tokstart < header_end; tokstart++ )
     {
         if( *tokstart == 0x20 )
             continue;
@@ -225,7 +225,7 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
 
 static int read_frame_internal( cli_pic_t *pic, y4m_hnd_t *h, int bit_depth_uc )
 {
-    size_t slen = strlen( Y4M_FRAME_MAGIC );
+    static const size_t slen = sizeof(Y4M_FRAME_MAGIC)-1;
     int pixel_depth = x264_cli_csp_depth_factor( pic->img.csp );
     int i = 0;
     char header[16];



More information about the x264-devel mailing list