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)