From: Willy Tarreau Date: Wed, 10 Jan 2024 10:28:28 +0000 (+0100) Subject: CLEANUP: http: avoid duplicating literals in find_http_meth() X-Git-Tag: v3.0-dev2~57 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59c01f1091c3f7d7c72d7e456ad2b9d70ca46081;p=thirdparty%2Fhaproxy.git CLEANUP: http: avoid duplicating literals in find_http_meth() 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). --- diff --git a/src/http.c b/src/http.c index 57750a2a73..072762d858 100644 --- a/src/http.c +++ b/src/http.c @@ -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_ (enum) matching http status code.