]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: tools: inline hex2i()
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Oct 2012 22:58:22 +0000 (00:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Oct 2012 23:13:24 +0000 (01:13 +0200)
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.

include/common/standard.h
src/standard.c

index dbb219a09c6500d335507195bf989b9085adefd7..e795df71715e83d95625df70a9f653a9daea7cb4 100644 (file)
@@ -180,9 +180,19 @@ extern int ishex(char s);
 
 /*
  * 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
index 76031e95625837a7337b507defcf111a9664dd49..c26d7a035f3e4bf432ae6fd7686eceb91c9e0604 100644 (file)
@@ -483,21 +483,6 @@ int ishex(char s)
        return 0;
 }
 
-/*
- * 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