From patchwork Tue Feb 23 04:32:11 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: 25914 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 05315449271 for ; Tue, 23 Feb 2021 06:32:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E5E5168A98D; Tue, 23 Feb 2021 06:32:28 +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 BCD3368A17B for ; Tue, 23 Feb 2021 06:32:20 +0200 (EET) Received: from mx0.ehosting.ca (localhost [127.0.0.1]) by mx0.i-mecca.net (Postfix) with ESMTP id 0D84B161621 for ; Mon, 22 Feb 2021 20:32:18 -0800 (PST) Received: from ns2.i-mecca.net (unknown [192.168.1.2]) by mx0.i-mecca.net (Postfix) with ESMTP id 7E2311615CB for ; Mon, 22 Feb 2021 20:32:17 -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=FqNuSJe5noWf4GvIoImVFBesphxtey4ghBtkhnjCwIAxHltoAyPg7YPKdi/4g79upG 4zmNjkAO4xmzy57cBrSYpaDa0pMCkYhQ75Ws37LQPiLnMKGYwVaPbjimuhnBzaEgp2df BJpWnmAQreRH91+KFAsrgVaTgo2AsRn6ruz3lVxBpoCfSAi1Whj3FRnR9IJrZLHGL0e4 nMHEHESA+ytu1J1rVqAt3/9AXyYMC9LO8ynnkZkvr+MmU5pL6J/uImIl7Gp//KNbqrmV la+LmfDU2fegDXl+wTuuv7lfvdH/nLU3hT8WtCWge3T8C2hMqMAAViKrICX3EN3ahGm9 VvSQ== 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 12DD1300027 for ; Mon, 22 Feb 2021 23:32:15 -0500 (EST) From: Jose Da Silva To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Feb 2021 20:32:11 -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.11427.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; } /*