[core] perf: copy small strings; better buf reuse
copy small strings to write queue for better buffer reuse (instead of swapping with larger buffers in write chunkqueue)
This commit is contained in:
parent
23c72fc606
commit
e7c840502a
|
@ -310,12 +310,11 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
|
|||
}
|
||||
|
||||
if (!con->file_finished) {
|
||||
buffer *b;
|
||||
buffer *b = srv->tmp_buf;
|
||||
|
||||
buffer_reset(con->physical.path);
|
||||
|
||||
con->file_finished = 1;
|
||||
b = buffer_init();
|
||||
|
||||
/* build default error-page */
|
||||
buffer_copy_string_len(b, CONST_STR_LEN(
|
||||
|
@ -339,8 +338,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
|
|||
"</html>\n"
|
||||
));
|
||||
|
||||
(void)http_chunk_append_buffer(srv, con, b);
|
||||
buffer_free(b);
|
||||
(void)http_chunk_append_mem(srv, con, CONST_BUF_LEN(b));
|
||||
|
||||
http_header_response_set(con, HTTP_HEADER_CONTENT_TYPE, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("text/html"));
|
||||
}
|
||||
|
|
|
@ -325,8 +325,7 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path,
|
|||
if (!error) {
|
||||
if (multipart) {
|
||||
/* write boundary-header */
|
||||
buffer *b = buffer_init();
|
||||
|
||||
buffer *b = srv->tmp_buf;
|
||||
buffer_copy_string_len(b, CONST_STR_LEN("\r\n--"));
|
||||
buffer_append_string_len(b, boundary, sizeof(boundary)-1);
|
||||
|
||||
|
@ -347,8 +346,7 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path,
|
|||
buffer_append_string_len(b, CONST_STR_LEN("\r\n\r\n"));
|
||||
|
||||
con->response.content_length += buffer_string_length(b);
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
}
|
||||
|
||||
chunkqueue_append_file(con->write_queue, path, start, end - start + 1);
|
||||
|
@ -361,15 +359,13 @@ static int http_response_parse_range(server *srv, connection *con, buffer *path,
|
|||
|
||||
if (multipart) {
|
||||
/* add boundary end */
|
||||
buffer *b = buffer_init();
|
||||
|
||||
buffer *b = srv->tmp_buf;
|
||||
buffer_copy_string_len(b, "\r\n--", 4);
|
||||
buffer_append_string_len(b, boundary, sizeof(boundary)-1);
|
||||
buffer_append_string_len(b, "--\r\n", 4);
|
||||
|
||||
con->response.content_length += buffer_string_length(b);
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
|
||||
/* set header-fields */
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ static void http_chunk_append_len(server *srv, connection *con, uintmax_t len) {
|
|||
buffer_append_uint_hex(b, len);
|
||||
buffer_append_string_len(b, CONST_STR_LEN("\r\n"));
|
||||
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
}
|
||||
|
||||
static int http_chunk_append_file_open_fstat(server *srv, connection *con, buffer *fn, struct stat *st) {
|
||||
|
|
|
@ -371,7 +371,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
case SSI_ECHO_USER_NAME: {
|
||||
struct passwd *pw;
|
||||
|
||||
b = buffer_init();
|
||||
b = srv->tmp_buf;
|
||||
#ifdef HAVE_PWD_H
|
||||
if (NULL == (pw = getpwuid(st->st_uid))) {
|
||||
buffer_copy_int(b, st->st_uid);
|
||||
|
@ -381,8 +381,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
#else
|
||||
buffer_copy_int(b, st->st_uid);
|
||||
#endif
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
break;
|
||||
}
|
||||
case SSI_ECHO_LAST_MODIFIED: {
|
||||
|
@ -580,7 +579,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
|
||||
switch (ssicmd) {
|
||||
case SSI_FSIZE:
|
||||
b = buffer_init();
|
||||
b = srv->tmp_buf;
|
||||
if (p->sizefmt) {
|
||||
int j = 0;
|
||||
const char *abr[] = { " B", " kB", " MB", " GB", " TB", NULL };
|
||||
|
@ -594,8 +593,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
} else {
|
||||
buffer_copy_int(b, stb.st_size);
|
||||
}
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
break;
|
||||
case SSI_FLASTMOD:
|
||||
if (0 == strftime(buf, sizeof(buf), p->timefmt->ptr, localtime(&t))) {
|
||||
|
@ -719,7 +717,8 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
case SSI_PRINTENV:
|
||||
if (p->if_is_false) break;
|
||||
|
||||
b = buffer_init();
|
||||
b = srv->tmp_buf;
|
||||
buffer_string_set_length(b, 0);
|
||||
for (i = 0; i < p->ssi_vars->used; i++) {
|
||||
data_string *ds = (data_string *)p->ssi_vars->data[p->ssi_vars->sorted[i]];
|
||||
|
||||
|
@ -736,9 +735,7 @@ static int process_ssi_stmt(server *srv, connection *con, handler_ctx *p, const
|
|||
buffer_append_string_encoded(b, CONST_BUF_LEN(ds->value), ENCODING_MINIMAL_XML);
|
||||
buffer_append_string_len(b, CONST_STR_LEN("\n"));
|
||||
}
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
break;
|
||||
case SSI_EXEC: {
|
||||
const char *cmd = NULL;
|
||||
|
|
|
@ -356,9 +356,8 @@ URIHANDLER_FUNC(mod_uploadprogress_uri_handler) {
|
|||
http_header_response_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("Expires"), CONST_STR_LEN("Thu, 19 Nov 1981 08:52:00 GMT"));
|
||||
http_header_response_set(con, HTTP_HEADER_CACHE_CONTROL, CONST_STR_LEN("Cache-Control"), CONST_STR_LEN("no-store, no-cache, must-revalidate, post-check=0, pre-check=0"));
|
||||
|
||||
b = buffer_init();
|
||||
|
||||
/* prepare XML */
|
||||
b = srv->tmp_buf;
|
||||
buffer_copy_string_len(b, CONST_STR_LEN(
|
||||
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
|
||||
"<upload>"
|
||||
|
@ -371,14 +370,7 @@ URIHANDLER_FUNC(mod_uploadprogress_uri_handler) {
|
|||
buffer_append_string_len(b, CONST_STR_LEN(
|
||||
"</received>"
|
||||
"</upload>"));
|
||||
|
||||
#if 0
|
||||
log_error_write(srv, __FILE__, __LINE__, "sb", "...", b);
|
||||
#endif
|
||||
|
||||
chunkqueue_append_buffer(con->write_queue, b);
|
||||
buffer_free(b);
|
||||
|
||||
chunkqueue_append_mem(con->write_queue, CONST_BUF_LEN(b));
|
||||
return HANDLER_FINISHED;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue