[FFmpeg-devel] [PATCH 3/4] avcodec/xpm: Minor speed increase for mod_strcspn() use reject pointer

Jose Da Silva digital at joescat.com
Tue Feb 23 06:32:16 EET 2021


Incrementing pointer *pr once is faster than computing reject[j] for each
time we need it.

Signed-off-by: Jose Da Silva <digital at joescat.com>
---
 libavcodec/xpmdec.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c
index 92a568041c..be5277e637 100644
--- a/libavcodec/xpmdec.c
+++ b/libavcodec/xpmdec.c
@@ -211,7 +211,8 @@ static unsigned int hex_char_to_number(uint8_t x)
  */
 static size_t mod_strcspn(const char *string, const char *reject)
 {
-    int i, j;
+    const char *pr;
+    int i;

     if (string == 0)
         return 0;
@@ -226,11 +227,8 @@ static size_t mod_strcspn(const char *string, const char *reject)
             while (string[i] && string[i] != '\n')
                 i++;
         } else if (reject) {
-            for (j = 0; reject[j]; j++) {
-                if (string[i] == reject[j])
-                    break;
-            }
-            if (reject[j])
+            for (pr = reject; *pr && *pr != string[i]; pr++);
+            if (*pr)
                 break;
         }
     }
--
2.30.1



More information about the ffmpeg-devel mailing list