OPTIM: tools: inline hex2i()
This tiny function was not inlined because initially not much used.
However it's been used un the chunk parser for a while and it became
one of the most CPU-cycle eater there. By inlining it, the chunk parser
speed was increased by 74 %. We're almost 3 times faster than original
with just the last 4 commits.
diff --git a/include/common/standard.h b/include/common/standard.h
index dbb219a..e795df7 100644
--- a/include/common/standard.h
+++ b/include/common/standard.h
@@ -180,9 +180,19 @@
/*
* Return integer equivalent of character <c> for a hex digit (0-9, a-f, A-F),
- * otherwise -1.
+ * otherwise -1. This compact form helps gcc produce efficient code.
*/
-extern int hex2i(int c);
+static inline int hex2i(int c)
+{
+ if ((unsigned char)(c -= '0') > 9) {
+ if ((unsigned char)(c -= 'A' - '0') > 5 &&
+ (unsigned char)(c -= 'a' - 'A') > 5)
+ c = -11;
+ c += 10;
+ }
+ return c;
+}
+
/*
* Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
diff --git a/src/standard.c b/src/standard.c
index 76031e9..c26d7a0 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -484,21 +484,6 @@
}
/*
- * Return integer equivalent of character <c> for a hex digit (0-9, a-f, A-F),
- * otherwise -1. This compact form helps gcc produce efficient code.
- */
-int hex2i(int c)
-{
- if ((unsigned char)(c -= '0') > 9) {
- if ((unsigned char)(c -= 'A' - '0') > 5 &&
- (unsigned char)(c -= 'a' - 'A') > 5)
- c = -11;
- c += 10;
- }
- return c;
-}
-
-/*
* Checks <name> for invalid characters. Valid chars are [A-Za-z0-9_:.-]. If an
* invalid character is found, a pointer to it is returned. If everything is
* fine, NULL is returned.