]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/xbmenc: Pre-compute variables once for parse_str_int()
authorJose Da Silva <digital@joescat.com>
Mon, 1 Feb 2021 03:50:57 +0000 (19:50 -0800)
committerPaul B Mahol <onemda@gmail.com>
Wed, 3 Feb 2021 15:03:15 +0000 (16:03 +0100)
Some compilers are very intuitive, and others are not so much, so let's
pre-compute the variables e and keylen outside the for loop. Ensuring a
minor speed increase regardless of if compiler is smart enough to solve
this improvement for itself, or not.

Signed-off-by: Joe Da Silva <digital@joescat.com>
libavcodec/xbmdec.c

index 2ce70204cf46d9aade8ef3f61cabcb82e240a1f7..b783d5abe5ee8d827b1489d7864a0df146f53f39 100644 (file)
@@ -39,11 +39,14 @@ static int convert(uint8_t x)
 
 static int parse_str_int(const uint8_t *p, const uint8_t *end, const uint8_t *key)
 {
-    for(; p<end - strlen(key); p++) {
-        if (!memcmp(p, key, strlen(key)))
+    int keylen = strlen(key);
+    const uint8_t *e = end - keylen;
+
+    for(; p < e; p++) {
+        if (!memcmp(p, key, keylen))
             break;
     }
-    p += strlen(key);
+    p += keylen;
     if (p >= end)
         return INT_MIN;