something like: diff --git a/lib/http.c b/lib/http.c index c036d877e..b62dec269 100644 --- a/lib/http.c +++ b/lib/http.c @@ -1423,17 +1423,17 @@ CURLcode Curl_buffer_send(struct dynbuf *in, * Pass headers WITH the colon. */ bool -Curl_compareheader(const char *headerline, /* line to check */ +Curl_compareheader_ex(const char *headerline, /* line to check */ const char *header, /* header keyword _with_ colon */ - const char *content) /* content string to find */ + size_t hlen, + const char *content, + size_t clen) /* content string to find */ { /* RFC2616, section 4.2 says: "Each header field consists of a name followed * by a colon (":") and the field value. Field names are case-insensitive. * The field value MAY be preceded by any amount of LWS, though a single SP * is preferred." */
- size_t hlen = strlen(header); - size_t clen; size_t len; const char *start; const char *end; @@ -1456,11 +1456,10 @@ Curl_compareheader(const char *headerline, /* line to check */ if(!end) /* hm, there's no line ending here, use the zero byte! */ - end = strchr(start, '\0'); + end = start + strlen(start); } len = end-start; /* length of the content part of the input line */ - clen = strlen(content); /* length of the word to find */ /* find the content string in the rest of the line */ for(; len >= clen; len--, start++) { diff --git a/lib/http.h b/lib/http.h index b4aaba2a2..da7409825 100644 --- a/lib/http.h +++ b/lib/http.h @@ -44,10 +44,15 @@ extern const struct Curl_handler Curl_handler_http; extern const struct Curl_handler Curl_handler_https; #endif +#define Curl_compareheader(headerline, header, content) \ + Curl_compareheader_ex(headerline, header, strlen(header), content, strlen(content)) + /* Header specific functions */ -bool Curl_compareheader(const char *headerline, /* line to check */ +bool Curl_compareheader_ex(const char *headerline, /* line to check */ const char *header, /* header keyword _with_ colon */ - const char *content); /* content string to find */ + size_t hlen, /* strlen of header */ + const char *content, /* content string to find */ + size_t clen); /* content string length */ char *Curl_copy_header_value(const char *header); With optimization enabled will probably do what you want. On Fri, Feb 4, 2022 at 8:00 AM Cristian Rodríguez <crrodrig...@opensuse.org> wrote: > > On Thu, Feb 3, 2022 at 10:09 PM Henrik Holst via curl-library > <curl-library@lists.haxx.se> wrote: > > > 23% of those for curl.se and 8% for google.com is due to > > Curl_compareheader, this looks like an internal only function and every > > single use inside curl is using string literals so we can replace them all > > with a compile time sizeof, if patches for this would be accepted then I > > would be happy to provide such. > > Well.. add a size_t header_len and content_len parameter to > Curl_compareheader .. or provide an inline version of it, any compiler > from the last decade will then do constant folding on strlen("test") > when optimization is enabled. -- Unsubscribe: https://lists.haxx.se/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.html