From patchwork Tue Feb 23 04:32:19 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: 25916 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 01342449271 for ; Tue, 23 Feb 2021 06:32:32 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D845968A315; Tue, 23 Feb 2021 06:32:31 +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 BE8C168AA2A for ; Tue, 23 Feb 2021 06:32:22 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 5CB7F1616B5 for ; Mon, 22 Feb 2021 20:32:21 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id BE46D1615CB for ; Mon, 22 Feb 2021 20:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joescat.com; s=mail; h=date:from:to:subject; bh=FKxG72+RJEH6sRxYTUG8w9K9c0lCfQxtZvV245pwFZA=; b=oxc9HafJhcSniQr+p1R2LyYbvhaOP+Fp+wc1k/ntITkEz1WfGipBQtVsgk4jGwJx1S FeeS4HsG0V7GcykoIlVeNBugflt3Qv4bFeHHKoRDllSTvRnnHzJubA6mJUtTZZZxuhXo qW0y1sifuEtWEuuWkQGbdSuet27AbPD/rjNkxGsvWD4fCF/a5AD8wSHhth2f7ypdzkBq ixlkFzvHpvFOtxyY/i9n4/BBXHV/8Q6OrE6n4gIKD2hPg0MSWQobNXJfWiQkI23yzyLv RXsSupZC/ks2oXJ+tdfLKww9q5ZK3NJqU8n/wU1XonJPZ51rQk9xnsvArVlbvtpPsgCI Fidg== 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 4C2FE300027 for ; Mon, 22 Feb 2021 23:32:19 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Feb 2021 20:32:19 -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: <202102222032.20012.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 be5277e637..9a50bb6a71 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 == 0) 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)