]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: h1: make use of the multi-byte matching functions
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 13:57:15 +0000 (15:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 14:05:38 +0000 (16:05 +0200)
Instead of leaving the hard-coded non-trivial operations in the H1
parsing code, let's just rely on the new intops functions that do the
same and that are less prone to being accidentally touched. It was
verified that the resulting code is exactly the same.

src/h1.c

index 0a548937a66507c427dcd0a9588e8306021ad28e..e4181493fb8fefb228da11131145a1626424c13e 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -575,9 +575,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
 #ifdef HA_UNALIGNED_LE
                /* speedup: skip bytes not between 0x24 and 0x7e inclusive */
                while (ptr <= end - sizeof(int)) {
-                       uint x = *(uint *)ptr;
-
-                       if (((x - 0x24242424) | (0x7e7e7e7e - x)) & 0x80808080U)
+                       if (is_char4_outside(*(uint *)ptr, 0x24, 0x7e))
                                break;
 
                        ptr += sizeof(int);
@@ -927,14 +925,14 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                 */
 #ifdef HA_UNALIGNED_LE64
                while (ptr <= end - sizeof(long)) {
-                       if ((*(long *)ptr - 0x0e0e0e0e0e0e0e0eULL) & 0x8080808080808080ULL)
+                       if (is_char8_below_opt(*(ulong *)ptr, 0x0e))
                                goto http_msg_hdr_val2;
                        ptr += sizeof(long);
                }
 #endif
 #ifdef HA_UNALIGNED_LE
                while (ptr <= end - sizeof(int)) {
-                       if ((*(int*)ptr - 0x0e0e0e0e) & 0x80808080)
+                       if (is_char4_below_opt(*(uint *)ptr, 0x0e))
                                goto http_msg_hdr_val2;
                        ptr += sizeof(int);
                }