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