diff mbox series

[FFmpeg-devel,1/4] avcodec/xpm: Minor speed increase to function hex_char_to_number()

Message ID 202102252134.46962.digital@joescat.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/xpm: Minor speed increase to function hex_char_to_number()
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Jose Da Silva Feb. 26, 2021, 5:34 a.m. UTC
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@joescat.com>
---
 libavcodec/xpmdec.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

--
2.30.1
diff mbox series

Patch

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

 /*