mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-02 01:20:49 +00:00
OPTIM: http: optimize lookup of comma and quote in header values
http_find_header2() relies on find_hdr_value_end() to find the comma delimiting a header field value, which also properly handles double quotes and backslashes within quotes. In fact double quotes are very rare, and commas happen once every multiple characters, especially with cookies where a full block can be found at once. So it makes sense to optimize this function to speed up the lookup of the first block before the quote. This change increases the performance from 212k to 217k req/s when requests contain a 1kB cookie (+2.5%). We don't care about going back into the fast parser after the first quote, as it may needlessly make the parser more complex for very marginal gains.
This commit is contained in:
parent
5f10ea30f4
commit
e6d9c21059
@ -836,6 +836,25 @@ char *find_hdr_value_end(char *s, const char *e)
|
||||
int quoted, qdpair;
|
||||
|
||||
quoted = qdpair = 0;
|
||||
|
||||
#if defined(__x86_64__) || \
|
||||
defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \
|
||||
defined(__ARM_ARCH_7A__)
|
||||
/* speedup: skip everything not a comma nor a double quote */
|
||||
for (; s <= e - sizeof(int); s += sizeof(int)) {
|
||||
unsigned int c = *(int *)s; // comma
|
||||
unsigned int q = c; // quote
|
||||
|
||||
c ^= 0x2c2c2c2c; // contains one zero on a comma
|
||||
q ^= 0x22222222; // contains one zero on a quote
|
||||
|
||||
c = (c - 0x01010101) & ~c; // contains 0x80 below a comma
|
||||
q = (q - 0x01010101) & ~q; // contains 0x80 below a quote
|
||||
|
||||
if ((c | q) & 0x80808080)
|
||||
break; // found a comma or a quote
|
||||
}
|
||||
#endif
|
||||
for (; s < e; s++) {
|
||||
if (qdpair) qdpair = 0;
|
||||
else if (quoted) {
|
||||
|
Loading…
Reference in New Issue
Block a user