diff mbox series

[FFmpeg-devel,2/4] avcodec/xbmenc: Pre-compute variables once for parse_str_int()

Message ID 202101311950.57434.digital@joescat.com
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avcodec/xbmenc: substitute end instead of recalculating end
Related show


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

Jose Da Silva Feb. 1, 2021, 3:50 a.m. UTC
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 | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff mbox series


diff --git a/libavcodec/xbmdec.c b/libavcodec/xbmdec.c
index 2ce70204cf..b783d5abe5 100644
--- a/libavcodec/xbmdec.c
+++ b/libavcodec/xbmdec.c
@@ -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))
-    p += strlen(key);
+    p += keylen;
     if (p >= end)
         return INT_MIN;