[FFmpeg-devel] [PATCH 2/4] avcodec/xpm: Minor speed increase for mod_strcspn() {string, reject}==0
Jose Da Silva
digital at joescat.com
Fri Feb 26 07:34:53 EET 2021
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 at joescat.com>
---
libavcodec/xpmdec.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
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;
}
}
--
2.30.1
More information about the ffmpeg-devel
mailing list