From patchwork Fri Feb 26 05:34:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 25996 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 62A7944BAB1 for ; Fri, 26 Feb 2021 07:34:56 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4EAAC68A67E; Fri, 26 Feb 2021 07:34:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 73DC268A497 for ; Fri, 26 Feb 2021 07:34:49 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 27E2E1615C4 for ; Thu, 25 Feb 2021 21:34:48 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id 927FE161488 for ; Thu, 25 Feb 2021 21:34:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=5Jq4Crn5/XuZG7HuCF45GNwjZs9PBVsqJdvWgixU4Ls=; b=Ekjy7XsPn4rGSjoo8iL8ngNDD/Aa+9t7cnHKydAsHAnXkSOsaYtRYhqhhkwKsL7c47 F0fltKhZKrMe8tMok3s9KTotp9rGQRXQRd//8bZhvDIDOChsfzLkqQC8TxNxYB63bOeS H42rQrMQGXfBoC4AAeYhH4VYT1LLyhOYtGFsJ1YwgotKkeaN48QRv53hVV/wWiE4BgPw z/iXA7M1CE6P+SyGzszE1OTRxDpPgjekHF2enwkVCIbveNgEkWSjaD35dE34vaWSX7Ch b+d50C906k5aFfH0gTNPNdgZ0iiakOZZu1jIWxRBUIO8W+lmbBCTnH2TGHGzQ9r+B/rl +Zhw== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id 304CF300209 for ; Fri, 26 Feb 2021 00:34:46 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Feb 2021 21:34:46 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202102252134.46962.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/xpm: Minor speed increase to function hex_char_to_number() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Search for 0 to 9 first as this is 10/16th of possible choices we want, then search for lowercase 6/16th, or uppercase 6/16th possible choices. This gives us a minor speed increase similar to xbmdec.c nibble search. Some modern compilers complain if using "unsigned" without using "int". Signed-off-by: Jose Da Silva --- libavcodec/xpmdec.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) -- 2.30.1 diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c index 922dfc0f67..5aab46c52d 100644 --- a/libavcodec/xpmdec.c +++ b/libavcodec/xpmdec.c @@ -191,17 +191,19 @@ static const ColorEntry color_table[] = { { "YellowGreen", 0xFF9ACD32 } }; -static unsigned hex_char_to_number(uint8_t x) +static unsigned int hex_char_to_number(uint8_t x) { - if (x >= 'a' && x <= 'f') - x -= 'a' - 10; - else if (x >= 'A' && x <= 'F') - x -= 'A' - 10; - else if (x >= '0' && x <= '9') - x -= '0'; - else - x = 0; - return x; + int ret = 0; + + if (x <= '9') { + if (x >= '0') + ret = x - '0'; + } else if (x >= 'a') { + if (x <= 'f') + ret = x - ('a' - 10); + } else if (x >= 'A' && x <= 'F') + ret = x - ('A' - 10); + return ret; } /* From patchwork Fri Feb 26 05:34:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 25998 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 5791F44BAB1 for ; Fri, 26 Feb 2021 07:35:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 404A568A6EB; Fri, 26 Feb 2021 07:35:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF1B368A199 for ; Fri, 26 Feb 2021 07:34:55 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 42E98161488 for ; Thu, 25 Feb 2021 21:34:54 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id AF7D51615F7 for ; Thu, 25 Feb 2021 21:34:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=UVoLCIUtT7cgUY6of5mnM0VyEKoWwPvRxFuiPzUP6wk=; b=Vgm3JE1lDCnh63SM7niU+Me3Q40upczTMGdP4OozyBLDc/mRecV9ZbrunrV9SZJJvq pPjSu7L0wpETuNpGFHcP7I+OW+Zcfv0pZ8KboMLT9DAK7X2l7JX0K+lTS8KGl+TNlUct lj0A9C4YxvCDWT0yoyGPh+4XgsX9bX2q7L2HCT+DVqs4FvsEjKk9JUvwwECGLhy9I/lq DPDWQ0ikSMyMESTm7IzsnixJTkFbrKPM+mfNyfmzCdOsb+w+8s+3ClIahmYwcdTKV+HI goDgycYXT+reuYmtHmY+QzqDvRLD0IxpFPJD3RjcTBDKoKV2xZQh6kwhbkBVUP/P4tfD seTw== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id 512A430020E for ; Fri, 26 Feb 2021 00:34:52 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Feb 2021 21:34:53 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202102252134.53108.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/xpm: Minor speed increase for mod_strcspn() {string, reject}==0 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- libavcodec/xpmdec.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.30.1 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; } } From patchwork Fri Feb 26 05:34:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 25999 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7960B44BC5C for ; Fri, 26 Feb 2021 07:35:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 62EC468A73D; Fri, 26 Feb 2021 07:35:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AABEC68A71F for ; Fri, 26 Feb 2021 07:35:02 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 298001615F7 for ; Thu, 25 Feb 2021 21:35:01 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id 8E25F1615C4 for ; Thu, 25 Feb 2021 21:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=acL1WRdyjkSAkUQQ3mAT+wNBv7QRPitjazcK1LyN/gM=; b=cCVQwlgCxWjTRe/1hLyD72hYY6mdC9ksgULQ9+ngvXI336oD/L7JlH6Du1l6uIPJDF 5J215ZqFrOLUIqQJFbGkh4XI0SVIJn+gPa1jvk/wjZmFEt4N9q9G4zBck9Sy+zU7dwZj Z0tRo0rjIoeSP6wDeLYmRt0awlxcPGo1U0NuoIdapxli5dlP46WoTscr9SOcZnv270VA kQIMHqnIUEdb/Q4uDMigXRIQVfRFML7YWlyrw97jwl/rKeSIW6VwmE6Av2v+DsM4epvi WGrVBSzEYprGJlh/BEbrQ4DSb/4EDPAJSPR5whVbv5l0HmBEN+ghh0TbQo+FcrHLH3rA iI4A== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id 32F3430020E for ; Fri, 26 Feb 2021 00:34:59 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Feb 2021 21:34:59 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202102252134.59980.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/xpm: Minor speed increase for mod_strcspn() use reject pointer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Incrementing pointer *pr once is faster than computing reject[j] for each time we need it. Signed-off-by: Jose Da Silva --- libavcodec/xpmdec.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) -- 2.30.1 diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c index 66a9a8008c..7b3d3a7ff5 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) 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; } } From patchwork Fri Feb 26 05:35:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Da Silva X-Patchwork-Id: 26000 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6448C44BC5C for ; Fri, 26 Feb 2021 07:35:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4539868A682; Fri, 26 Feb 2021 07:35:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0-10.i-mecca.net (mx0-10.i-mecca.net [76.74.184.244]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB9FE68A758 for ; Fri, 26 Feb 2021 07:35:08 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 67DF71615C4 for ; Thu, 25 Feb 2021 21:35:07 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id C9CB3161488 for ; Thu, 25 Feb 2021 21:35:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=7XXdghuoXBcYZxluR3N1t8SsSJxKklZg893YwVgM4CA=; b=lV6kTMmjQfy9rDjsi2AiYQu9ZmyqSxLS/3KKWHpJG7fMAXNxVyibJ4ctuaIMc6NAKv pcdAp5Uqrn91PGJLy91sp5NhQUWKFLIohR4HiQ0F3IclMB5ZU59LTsKkskprjW2P0OMA +Mhs2LEsYih6TkIAljs7CX4YiY1cBn3K+23y98UOuhibr+yuejcGq8ObNAvllqe5tqsN v+LcRj3KK/e0J/D7TlIRDpLnodne3lQVFe6wFxJpj3thbhgsuyNKcefb1tnY2GsRSMwG ETO6B0C6xbKyWVKVXVWnXBOb8NPWX6pbs1tVsPlusktJmkGnyQ7HGReEFKP/HUvjxQiV 9fhQ== X-MES: 1.0 X-MM: 1.0 Received: from drived.localnet (d66-183-117-75.bchsia.telus.net [66.183.117.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ns2.i-mecca.net (Postfix) with ESMTPSA id 48FD2300211 for ; Fri, 26 Feb 2021 00:35:05 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Feb 2021 21:35:05 -0800 User-Agent: KMail/1.13.7 (Linux/2.6.38.8-desktop586-10.mga; KDE/4.6.5; i686; ; ) MIME-Version: 1.0 Message-Id: <202102252135.05964.digital@joescat.com> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/xpm: Minor speed increase for mod_strcspn() use string pointer X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Incrementing pointer *ps once is faster than computing string[i] for each time we need it. Bug fix: For the remote possibility of a crazy-long comment section that overflows int, this fix can also return a value larger than sizeof(int). Signed-off-by: Jose Da Silva --- libavcodec/xpmdec.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) -- 2.30.1 diff --git a/libavcodec/xpmdec.c b/libavcodec/xpmdec.c index 7b3d3a7ff5..c7fbd38fe5 100644 --- a/libavcodec/xpmdec.c +++ b/libavcodec/xpmdec.c @@ -211,28 +211,27 @@ static unsigned int hex_char_to_number(uint8_t x) */ static size_t mod_strcspn(const char *string, const char *reject) { - const char *pr; - int i; + const char *ps, *pr; if (!string) return 0; - for (i = 0; string[i]; i++) { - if (string[i] == '/' && string[i+1] == '*') { - i += 2; - while (string[i] && (string[i] != '*' || string[i+1] != '/')) - i++; - i++; - } else if (string[i] == '/' && string[i+1] == '/') { - i += 2; - while (string[i] && string[i] != '\n') - i++; + for (ps = string; *ps; ps++) { + if (*ps == '/' && *(ps+1) == '*') { + ps += 2; + while (*ps && (*ps != '*' || *(ps+1) != '/')) + ps++; + ps++; + } else if (*ps == '/' && *(ps+1) == '/') { + ps += 2; + while (*ps && *ps != '\n') + ps++; } else if (reject) { - for (pr = reject; *pr && *pr != string[i]; pr++); + for (pr = reject; *pr && *pr != *ps; pr++); if (*pr) break; } } - return i; + return (ps - string); } static uint32_t color_string_to_rgba(const char *p, int len)