summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-01-21 23:49:34 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2020-01-21 23:49:34 -0500
commit4a45d58a8c92f5c47b03fddb92893a27c06df0f4 (patch)
tree9ab0f05888cd51fcc54a21d6d6482020927023e7
parent7b562e800443d792d182fd20eb410aaccd366d36 (diff)
downloadlighttpd1.4-personal/gstrauss/master.tar.gz
lighttpd1.4-personal/gstrauss/master.zip
[core] perf: tighten some code in some hot pathspersonal/gstrauss/master
-rw-r--r--src/buffer.c42
-rw-r--r--src/connections.c12
-rw-r--r--src/http_header.c7
3 files changed, 34 insertions, 27 deletions
diff --git a/src/buffer.c b/src/buffer.c
index cc215776..1c567af2 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -723,7 +723,7 @@ void buffer_copy_string_encoded_cgi_varnames(buffer * const restrict b, const ch
* replaces non-printable characters with '_'
*/
-static void buffer_urldecode_internal(buffer *url, int is_query) {
+static void buffer_urldecode_internal(buffer * const url, const int is_query) {
unsigned char high, low;
char *src;
char *dst;
@@ -735,11 +735,17 @@ static void buffer_urldecode_internal(buffer *url, int is_query) {
src = (char*) url->ptr;
- while ('\0' != *src) {
- if ('%' == *src) break;
- if (is_query && '+' == *src) *src = ' ';
- src++;
+ if (!is_query) {
+ while ('\0' != *src && '%' != *src) ++src;
+ }
+ else {
+ for (; '\0' != *src && '%' != *src; ++src) {
+ if ('+' == *src) *src = ' ';
+ }
}
+
+ if ('\0' == *src) return;
+
dst = src;
while ('\0' != *src) {
@@ -923,23 +929,21 @@ void buffer_path_simplify(buffer *dest, buffer *src)
buffer_string_set_length(dest, out - start);
}
-void buffer_to_lower(buffer *b) {
- size_t i;
-
- for (i = 0; i < b->used; ++i) {
- char c = b->ptr[i];
- if (c >= 'A' && c <= 'Z') b->ptr[i] |= 0x20;
- }
+void buffer_to_lower(buffer * const b) {
+ char * const s = b->ptr;
+ for (uint32_t i = 0; i < b->used; ++i) {
+ char c = s[i];
+ if (c >= 'A' && c <= 'Z') s[i] |= 0x20;
+ }
}
-void buffer_to_upper(buffer *b) {
- size_t i;
-
- for (i = 0; i < b->used; ++i) {
- char c = b->ptr[i];
- if (c >= 'a' && c <= 'z') b->ptr[i] &= ~0x20;
- }
+void buffer_to_upper(buffer * const b) {
+ char * const s = b->ptr;
+ for (uint32_t i = 0; i < b->used; ++i) {
+ char c = s[i];
+ if (c >= 'a' && c <= 'z') s[i] &= ~0x20;
+ }
}
diff --git a/src/connections.c b/src/connections.c
index 16e94aca..c8db9df1 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -404,16 +404,20 @@ static int connection_handle_write_prepare(request_st * const r) {
r->http_status == 304) {
/* no Content-Body, no Content-Length */
http_header_response_unset(r, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"));
- } else if (qlen > 0 || r->http_method != HTTP_METHOD_HEAD) {
- /* qlen = 0 is important for Redirects (301, ...) as they MAY have
- * a content. Browsers are waiting for a Content otherwise
- */
+ } else if (qlen > 0) {
buffer * const tb = r->tmp_buf;
buffer_clear(tb);
buffer_append_int(tb, qlen);
http_header_response_set(r, HTTP_HEADER_CONTENT_LENGTH,
CONST_STR_LEN("Content-Length"),
CONST_BUF_LEN(tb));
+ } else if (r->http_method != HTTP_METHOD_HEAD) {
+ /* qlen = 0 is important for Redirects (301, ...) as they MAY have
+ * a content. Browsers are waiting for a Content otherwise
+ */
+ http_header_response_set(r, HTTP_HEADER_CONTENT_LENGTH,
+ CONST_STR_LEN("Content-Length"),
+ CONST_STR_LEN("0"));
}
}
} else {
diff --git a/src/http_header.c b/src/http_header.c
index 90142c93..f462c5ba 100644
--- a/src/http_header.c
+++ b/src/http_header.c
@@ -55,11 +55,10 @@ enum http_header_e http_header_hkey_get(const char * const s, const uint32_t sle
const struct keyvlenvalue * const kv = http_headers;
int i = slen < sizeof(http_headers_off) ? http_headers_off[slen] : -1;
if (i < 0) return HTTP_HEADER_OTHER;
- for (; slen == kv[i].vlen; ++i) {
- if (slen == kv[i].vlen
- && buffer_eq_icase_ssn(s, kv[i].value, slen))
+ do {
+ if (buffer_eq_icase_ssn(s, kv[i].value, slen))
return (enum http_header_e)kv[i].key;
- }
+ } while (slen == kv[++i].vlen);
return HTTP_HEADER_OTHER;
}