[FFmpeg-devel] [PATCH 1/4] avcodec/xpm: Minor speed increase to function hex_char_to_number()
Jose Da Silva
digital at joescat.com
Fri Feb 26 07:34:46 EET 2021
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 <digital at joescat.com>
---
libavcodec/xpmdec.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
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;
}
/*
--
2.30.1
More information about the ffmpeg-devel
mailing list