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; } }