diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-05-15 23:51:49 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-05-15 23:51:49 +0300 |
commit | 11350cbeafffca63ec71a93ebfa3e8a67451218d (patch) | |
tree | f24b4e432a0c4542cc1fa7bcc039c7a979abf7f1 | |
parent | 2a0871b731fb068bfab6acc04a473914149b87b0 (diff) | |
download | libmicrohttpd-11350cbeafffca63ec71a93ebfa3e8a67451218d.tar.gz libmicrohttpd-11350cbeafffca63ec71a93ebfa3e8a67451218d.zip |
More speedups by using predefined length of strings
-rw-r--r-- | src/microhttpd/connection.c | 32 | ||||
-rw-r--r-- | src/microhttpd/response.c | 16 |
2 files changed, 33 insertions, 15 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index d3f47d4d..b73e6d5a 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -1010,6 +1010,8 @@ MHD_lookup_connection_value_n (struct MHD_Connection *connection, | |||
1010 | * Case-insensitive match used for header names and tokens. | 1010 | * Case-insensitive match used for header names and tokens. |
1011 | * @param connection the connection to get values from | 1011 | * @param connection the connection to get values from |
1012 | * @param header the header name | 1012 | * @param header the header name |
1013 | * @param header_len the length of header, not including optional | ||
1014 | * terminating null-character | ||
1013 | * @param token the token to find | 1015 | * @param token the token to find |
1014 | * @param token_len the length of token, not including optional | 1016 | * @param token_len the length of token, not including optional |
1015 | * terminating null-character. | 1017 | * terminating null-character. |
@@ -1019,6 +1021,7 @@ MHD_lookup_connection_value_n (struct MHD_Connection *connection, | |||
1019 | static bool | 1021 | static bool |
1020 | MHD_lookup_header_token_ci (const struct MHD_Connection *connection, | 1022 | MHD_lookup_header_token_ci (const struct MHD_Connection *connection, |
1021 | const char *header, | 1023 | const char *header, |
1024 | size_t header_len, | ||
1022 | const char *token, | 1025 | const char *token, |
1023 | size_t token_len) | 1026 | size_t token_len) |
1024 | { | 1027 | { |
@@ -1026,12 +1029,15 @@ MHD_lookup_header_token_ci (const struct MHD_Connection *connection, | |||
1026 | 1029 | ||
1027 | if (NULL == connection || NULL == header || 0 == header[0] || NULL == token || 0 == token[0]) | 1030 | if (NULL == connection || NULL == header || 0 == header[0] || NULL == token || 0 == token[0]) |
1028 | return false; | 1031 | return false; |
1032 | |||
1029 | for (pos = connection->headers_received; NULL != pos; pos = pos->next) | 1033 | for (pos = connection->headers_received; NULL != pos; pos = pos->next) |
1030 | { | 1034 | { |
1031 | if ((0 != (pos->kind & MHD_HEADER_KIND)) && | 1035 | if ((0 != (pos->kind & MHD_HEADER_KIND)) && |
1036 | (header_len == pos->header_size) && | ||
1032 | ( (header == pos->header) || | 1037 | ( (header == pos->header) || |
1033 | (MHD_str_equal_caseless_(header, | 1038 | (MHD_str_equal_caseless_bin_n_(header, |
1034 | pos->header)) ) && | 1039 | pos->header, |
1040 | header_len)) ) && | ||
1035 | (MHD_str_has_token_caseless_ (pos->value, token, token_len))) | 1041 | (MHD_str_has_token_caseless_ (pos->value, token, token_len))) |
1036 | return true; | 1042 | return true; |
1037 | } | 1043 | } |
@@ -1045,13 +1051,14 @@ MHD_lookup_header_token_ci (const struct MHD_Connection *connection, | |||
1045 | * Token could be surrounded by spaces and tabs and delimited by comma. | 1051 | * Token could be surrounded by spaces and tabs and delimited by comma. |
1046 | * Case-insensitive match used for header names and tokens. | 1052 | * Case-insensitive match used for header names and tokens. |
1047 | * @param c the connection to get values from | 1053 | * @param c the connection to get values from |
1048 | * @param h the header name | 1054 | * @param h the static string of header name |
1049 | * @param tkn the static string of token to find | 1055 | * @param tkn the static string of token to find |
1050 | * @return true if token is found in specified header, | 1056 | * @return true if token is found in specified header, |
1051 | * false otherwise | 1057 | * false otherwise |
1052 | */ | 1058 | */ |
1053 | #define MHD_lookup_header_s_token_ci(c,h,tkn) \ | 1059 | #define MHD_lookup_header_s_token_ci(c,h,tkn) \ |
1054 | MHD_lookup_header_token_ci((c),(h),(tkn),MHD_STATICSTR_LEN_(tkn)) | 1060 | MHD_lookup_header_token_ci((c),(h),MHD_STATICSTR_LEN_(h),\ |
1061 | (tkn),MHD_STATICSTR_LEN_(tkn)) | ||
1055 | 1062 | ||
1056 | 1063 | ||
1057 | /** | 1064 | /** |
@@ -1649,7 +1656,7 @@ build_header_response (struct MHD_Connection *connection) | |||
1649 | if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state) | 1656 | if (MHD_CONNECTION_FOOTERS_RECEIVED == connection->state) |
1650 | { | 1657 | { |
1651 | reason_phrase = MHD_get_reason_phrase_for (rc); | 1658 | reason_phrase = MHD_get_reason_phrase_for (rc); |
1652 | MHD_snprintf_ (code, | 1659 | off = MHD_snprintf_ (code, |
1653 | sizeof (code), | 1660 | sizeof (code), |
1654 | "%s %u %s\r\n", | 1661 | "%s %u %s\r\n", |
1655 | (0 != (connection->responseCode & MHD_ICY_FLAG)) | 1662 | (0 != (connection->responseCode & MHD_ICY_FLAG)) |
@@ -1661,7 +1668,6 @@ build_header_response (struct MHD_Connection *connection) | |||
1661 | : MHD_HTTP_VERSION_1_1), | 1668 | : MHD_HTTP_VERSION_1_1), |
1662 | rc, | 1669 | rc, |
1663 | reason_phrase); | 1670 | reason_phrase); |
1664 | off = strlen (code); | ||
1665 | /* estimate size */ | 1671 | /* estimate size */ |
1666 | size = off + 2; /* +2 for extra "\r\n" at the end */ | 1672 | size = off + 2; /* +2 for extra "\r\n" at the end */ |
1667 | kind = MHD_HEADER_KIND; | 1673 | kind = MHD_HEADER_KIND; |
@@ -1864,11 +1870,13 @@ build_header_response (struct MHD_Connection *connection) | |||
1864 | if ( (pos->kind == kind) && | 1870 | if ( (pos->kind == kind) && |
1865 | (! ( (MHD_YES == must_add_close) && | 1871 | (! ( (MHD_YES == must_add_close) && |
1866 | (response_has_keepalive) && | 1872 | (response_has_keepalive) && |
1867 | (MHD_str_equal_caseless_(pos->header, | 1873 | (pos->header_size == MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONNECTION)) && |
1868 | MHD_HTTP_HEADER_CONNECTION)) && | 1874 | (MHD_str_equal_caseless_bin_n_(pos->header, |
1875 | MHD_HTTP_HEADER_CONNECTION, | ||
1876 | MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONNECTION))) && | ||
1869 | (MHD_str_equal_caseless_(pos->value, | 1877 | (MHD_str_equal_caseless_(pos->value, |
1870 | "Keep-Alive")) ) ) ) | 1878 | "Keep-Alive")) ) ) ) |
1871 | size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */ | 1879 | size += pos->header_size + pos->value_size + 4; /* colon, space, linefeeds */ |
1872 | } | 1880 | } |
1873 | /* produce data */ | 1881 | /* produce data */ |
1874 | data = MHD_pool_allocate (connection->pool, | 1882 | data = MHD_pool_allocate (connection->pool, |
@@ -1926,8 +1934,10 @@ build_header_response (struct MHD_Connection *connection) | |||
1926 | if ( (pos->kind == kind) && | 1934 | if ( (pos->kind == kind) && |
1927 | (! ( (MHD_YES == must_add_close) && | 1935 | (! ( (MHD_YES == must_add_close) && |
1928 | (response_has_keepalive) && | 1936 | (response_has_keepalive) && |
1929 | (MHD_str_equal_caseless_(pos->header, | 1937 | (pos->header_size == MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONNECTION)) && |
1930 | MHD_HTTP_HEADER_CONNECTION)) && | 1938 | (MHD_str_equal_caseless_bin_n_(pos->header, |
1939 | MHD_HTTP_HEADER_CONNECTION, | ||
1940 | MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONNECTION))) && | ||
1931 | (MHD_str_equal_caseless_(pos->value, | 1941 | (MHD_str_equal_caseless_(pos->value, |
1932 | "Keep-Alive")) ) ) ) | 1942 | "Keep-Alive")) ) ) ) |
1933 | off += MHD_snprintf_ (&data[off], | 1943 | off += MHD_snprintf_ (&data[off], |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 7d7e899b..f43ca541 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -199,18 +199,26 @@ MHD_del_response_header (struct MHD_Response *response, | |||
199 | { | 199 | { |
200 | struct MHD_HTTP_Header *pos; | 200 | struct MHD_HTTP_Header *pos; |
201 | struct MHD_HTTP_Header *prev; | 201 | struct MHD_HTTP_Header *prev; |
202 | size_t header_len; | ||
203 | size_t content_len; | ||
202 | 204 | ||
203 | if ( (NULL == header) || | 205 | if ( (NULL == header) || |
204 | (NULL == content) ) | 206 | (NULL == content) ) |
205 | return MHD_NO; | 207 | return MHD_NO; |
208 | header_len = strlen (header); | ||
209 | content_len = strlen (content); | ||
206 | prev = NULL; | 210 | prev = NULL; |
207 | pos = response->first_header; | 211 | pos = response->first_header; |
208 | while (NULL != pos) | 212 | while (NULL != pos) |
209 | { | 213 | { |
210 | if ((0 == strcmp (header, | 214 | if ((header_len == pos->header_size) && |
211 | pos->header)) && | 215 | (content_len == pos->value_size) && |
212 | (0 == strcmp (content, | 216 | (0 == memcmp (header, |
213 | pos->value))) | 217 | pos->header, |
218 | header_len)) && | ||
219 | (0 == memcmp (content, | ||
220 | pos->value, | ||
221 | content_len))) | ||
214 | { | 222 | { |
215 | free (pos->header); | 223 | free (pos->header); |
216 | free (pos->value); | 224 | free (pos->value); |