diff mbox series

[FFmpeg-devel,2/4] avcodec/xpm: Minor speed increase for mod_strcspn() {string, reject}==0

Message ID 202102252134.53108.digital@joescat.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/xpm: Minor speed increase to function hex_char_to_number() | expand

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

Jose Da Silva Feb. 26, 2021, 5:34 a.m. UTC
Test string==0 once before looping. This avoids testing 'string!=0'
i times inside the for i loop, (plus more checks for comments).

Test reject==0 once before looping. This avoids testing 'reject!=0'
i*[strlen(reject)+1] times inside the for j loop string.

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

--
2.30.1
diff mbox series

Patch

diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c
index 5aab46c52d..66a9a8008c 100644
--- a/libavcodec/xpmdec.c
+++ b/libavcodec/xpmdec.c
@@ -213,22 +213,24 @@  static size_t mod_strcspn(const char *string, const char *reject)
 {
     int i, j;

-    for (i = 0; string && string[i]; i++) {
+    if (!string)
+        return 0;
+    for (i = 0; string[i]; i++) {
         if (string[i] == '/' && string[i+1] == '*') {
             i += 2;
-            while ( string && string[i] && (string[i] != '*' || string[i+1] != '/') )
+            while (string[i] && (string[i] != '*' || string[i+1] != '/'))
                 i++;
             i++;
         } else if (string[i] == '/' && string[i+1] == '/') {
             i += 2;
-            while ( string && string[i] && string[i] != '\n' )
+            while (string[i] && string[i] != '\n')
                 i++;
-        } else {
-            for (j = 0; reject && reject[j]; j++) {
+        } else if (reject) {
+            for (j = 0; reject[j]; j++) {
                 if (string[i] == reject[j])
                     break;
             }
-            if (reject && reject[j])
+            if (reject[j])
                 break;
         }
     }