From fcce0e1e093b75b3edf4188fa95bb5a55398478a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 1 Apr 2022 17:16:44 +0200 Subject: [PATCH] OPTIM: hpack: read 32 bits at once when possible. As suggested in the comment, it's possible to read 32 bits at once in big-endian order, and now we have the functions to do this, so let's do it. This reduces the code on the fast path by 31 bytes on x86, and more importantly performs single-operation 32-bit reads instead of playing with shifts and additions. --- src/hpack-huff.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/hpack-huff.c b/src/hpack-huff.c index 9c63e28e8..35fa52d59 100644 --- a/src/hpack-huff.c +++ b/src/hpack-huff.c @@ -31,6 +31,7 @@ #include #include +#include struct huff { uint32_t c; /* code point */ @@ -1439,17 +1440,11 @@ int huff_dec(const uint8_t *huff, int hlen, char *out, int olen) while (shift >= 32) { curr = next; - /* read up to 4 bytes into next. FIXME: this should - * later be optimized to perform a single 32-bit big - * endian read when unaligned accesses are possible. - */ + /* read up to 4 bytes into next */ next = 0; if (huff + 4 <= huff_end) { - next = ((uint32_t)huff[0] << 24) + - ((uint32_t)huff[1] << 16) + - ((uint32_t)huff[2] << 8) + - (uint32_t)huff[3]; + next = read_n32(huff); huff += 4; } else {