]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: http: avoid duplicating literals in find_http_meth()
authorWilly Tarreau <w@1wt.eu>
Wed, 10 Jan 2024 10:28:28 +0000 (11:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Jan 2024 14:10:08 +0000 (15:10 +0100)
The function does the inverse of http_known_methods[], better rely on
that array with its indices, that makes the code clearer. Note that
we purposely don't use a loop because the compiler is able to build
an evaluation tree of the size checks and content checks that's very
efficient for the most common methods. Moving a few unimportant
entries even simplified the output code a little bit (they're now
groupped by size without changing anything for the first ones).

src/http.c

index 57750a2a735d77811ec864de0711c2bd8dc813b9..072762d8583f06e3b274f5fab4fca5c3aef16f0a 100644 (file)
@@ -352,15 +352,15 @@ enum http_meth_t find_http_meth(const char *str, const int len)
 {
        const struct ist m = ist2(str, len);
 
-       if      (isteq(m, ist("GET")))     return HTTP_METH_GET;
-       else if (isteq(m, ist("HEAD")))    return HTTP_METH_HEAD;
-       else if (isteq(m, ist("POST")))    return HTTP_METH_POST;
-       else if (isteq(m, ist("CONNECT"))) return HTTP_METH_CONNECT;
-       else if (isteq(m, ist("PUT")))     return HTTP_METH_PUT;
-       else if (isteq(m, ist("OPTIONS"))) return HTTP_METH_OPTIONS;
-       else if (isteq(m, ist("DELETE")))  return HTTP_METH_DELETE;
-       else if (isteq(m, ist("TRACE")))   return HTTP_METH_TRACE;
-       else                               return HTTP_METH_OTHER;
+       if      (isteq(m, http_known_methods[HTTP_METH_GET]))     return HTTP_METH_GET;
+       else if (isteq(m, http_known_methods[HTTP_METH_PUT]))     return HTTP_METH_PUT;
+       else if (isteq(m, http_known_methods[HTTP_METH_HEAD]))    return HTTP_METH_HEAD;
+       else if (isteq(m, http_known_methods[HTTP_METH_POST]))    return HTTP_METH_POST;
+       else if (isteq(m, http_known_methods[HTTP_METH_TRACE]))   return HTTP_METH_TRACE;
+       else if (isteq(m, http_known_methods[HTTP_METH_DELETE]))  return HTTP_METH_DELETE;
+       else if (isteq(m, http_known_methods[HTTP_METH_CONNECT])) return HTTP_METH_CONNECT;
+       else if (isteq(m, http_known_methods[HTTP_METH_OPTIONS])) return HTTP_METH_OPTIONS;
+       else                                                      return HTTP_METH_OTHER;
 }
 
 /* This function returns HTTP_ERR_<num> (enum) matching http status code.