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 <digi...@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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to