From 7a835f3cb0c5eab84199ad126098af30d94ca226 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 21 May 2021 11:31:35 +0200 Subject: [PATCH] MINOR: h1-htx: Use a correlation table to speed-up small chunks parsing Instead of using hex2i() to convert an hexa digit to an integer in the function parsing small chunks, we now use a table because it is faster. --- src/h1_htx.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/h1_htx.c b/src/h1_htx.c index adb96e1be..ec240a303 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -451,6 +451,17 @@ static size_t h1_copy_msg_data(struct htx **dsthtx, struct buffer *srcbuf, size_ return ret; } +static const char hextable[] = { + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, + -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, + -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 +}; + /* Generic function to parse the current HTTP chunk. It may be used to parsed * any kind of chunks, including incomplete HTTP chunks or splitted chunks * because the buffer wraps. This version tries to performed zero-copy on large @@ -598,7 +609,7 @@ static size_t h1_parse_full_contig_chunks(struct h1m *h1m, struct htx **dsthtx, goto end_parsing; /* Convert current character */ - c = hex2i(end[ridx]); + c = hextable[(unsigned char)end[ridx]]; /* not a hex digit anymore */ if (c < 0)