mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-09 00:27:08 +02:00
MINOR: hpack: simplify the len to bytes conversion
The len-to-bytes conversion can be slightly simplified and optimized by hardcoding a tree lookup. Just doing this increases by 1% the request rate on H2. It could be made almost branch-free by using fls() but it looks overkill for most situations since most headers are very short.
This commit is contained in:
parent
2df026fbce
commit
1526f1942c
@ -43,13 +43,18 @@
|
|||||||
*/
|
*/
|
||||||
static inline int len_to_bytes(size_t len)
|
static inline int len_to_bytes(size_t len)
|
||||||
{
|
{
|
||||||
if (len < 127)
|
ssize_t slen = len;
|
||||||
|
|
||||||
|
slen -= 127;
|
||||||
|
if (__builtin_expect(slen < 0, 1))
|
||||||
return 1;
|
return 1;
|
||||||
if (len < 127 + (1 << 7))
|
if (slen < (1 << 14)) {
|
||||||
|
if (__builtin_expect(slen < (1 << 7), 1))
|
||||||
return 2;
|
return 2;
|
||||||
if (len < 127 + (1 << 14))
|
else
|
||||||
return 3;
|
return 3;
|
||||||
if (len < 127 + (1 << 21))
|
}
|
||||||
|
if (slen < (1 << 21))
|
||||||
return 4;
|
return 4;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user