[multiple] prefer r->tmp_buf to p->tmp_buf

prefer per-request r->tmp_buf to per-module p->tmp_buf
to marginally increase buf reuse during each request.
(currently, r->tmp_buf == srv->tmp_buf)

(avoid some persistent memory allocations per-module,
 as those are not currently cleared/released periodically)
master
Glenn Strauss 2 years ago
parent 7b615d5d24
commit 062ea98bcb

@ -34,7 +34,6 @@ typedef struct {
plugin_config defaults;
plugin_config conf;
buffer tmp_buf;
array split_vals;
} plugin_data;
@ -51,7 +50,6 @@ static void mod_evhost_free_path_pieces(const buffer *path_pieces) {
FREE_FUNC(mod_evhost_free) {
plugin_data * const p = p_d;
free(p->tmp_buf.ptr);
array_free_data(&p->split_vals);
if (NULL == p->cvlist) return;
/* (init i to 0 if global context; to 1 to skip empty global context) */
@ -335,7 +333,7 @@ static handler_t mod_evhost_uri_handler(request_st * const r, void *p_d) {
/* missing even default(global) conf */
if (NULL == p->conf.path_pieces) return HANDLER_GO_ON;
buffer * const b = &p->tmp_buf;
buffer * const b = r->tmp_buf;/*(tmp_buf cleared before use in call below)*/
mod_evhost_build_doc_root_path(b, &p->split_vals, &r->uri.authority, p->conf.path_pieces);
if (!stat_cache_path_isdir(b)) {

@ -30,8 +30,6 @@ typedef struct {
PLUGIN_DATA;
plugin_config defaults;
plugin_config conf;
buffer tmp_buf;
} plugin_data;
typedef struct {
@ -46,7 +44,6 @@ INIT_FUNC(mod_mysql_vhost_init) {
/* cleanup the mysql connections */
FREE_FUNC(mod_mysql_vhost_cleanup) {
plugin_data * const p = p_d;
free(p->tmp_buf.ptr);
if (NULL == p->cvlist) return;
/* (init i to 0 if global context; to 1 to skip empty global context) */
for (int i = !p->cvlist[0].v.u2[1], used = p->nconfig; i < used; ++i) {
@ -291,7 +288,7 @@ REQUEST_FUNC(mod_mysql_vhost_handle_docroot) {
if (buffer_is_equal(c->server_name, &r->uri.authority)) goto GO_ON;
/* build and run SQL query */
buffer * const b = &p->tmp_buf;
buffer * const b = r->tmp_buf;
buffer_clear(b);
for (const char *ptr = p->conf.mysql_query->ptr, *d; *ptr; ptr = d+1) {
if (NULL != (d = strchr(ptr, '?'))) {

@ -22,7 +22,6 @@ typedef struct {
plugin_config defaults;
plugin_config conf;
buffer tmp_buf;
buffer last_root;
} plugin_data;
@ -32,7 +31,6 @@ INIT_FUNC(mod_simple_vhost_init) {
FREE_FUNC(mod_simple_vhost_free) {
plugin_data *p = p_d;
free(p->tmp_buf.ptr);
free(p->last_root.ptr);
}
@ -183,7 +181,7 @@ static handler_t mod_simple_vhost_docroot(request_st * const r, void *p_data) {
* are the two differences between mod_simple_vhost and mod_vhostdb) */
/* build document-root */
buffer * const b = &p->tmp_buf;
buffer * const b = r->tmp_buf;/*(tmp_buf cleared before use in call below)*/
const buffer *host = &r->uri.authority;
if ((!buffer_is_blank(host) && build_doc_root(r, p, b, host))
|| build_doc_root(r, p, b, (host = p->conf.default_host))) {

@ -35,8 +35,6 @@ typedef struct {
PLUGIN_DATA;
plugin_config defaults;
plugin_config conf;
buffer tmp_buf;
} plugin_data;
typedef struct {
@ -134,7 +132,6 @@ INIT_FUNC(mod_vhostdb_init) {
FREE_FUNC(mod_vhostdb_free) {
plugin_data *p = p_d;
free(p->tmp_buf.ptr);
if (NULL == p->cvlist) return;
/* (init i to 0 if global context; to 1 to skip empty global context) */
@ -273,8 +270,6 @@ static handler_t mod_vhostdb_found (request_st * const r, vhostdb_cache_entry *
REQUEST_FUNC(mod_vhostdb_handle_docroot) {
plugin_data *p = p_d;
vhostdb_cache_entry *ve;
const http_vhostdb_backend_t *backend;
buffer *b;
/* no host specified? */
if (buffer_is_blank(&r->uri.authority)) return HANDLER_GO_ON;
@ -291,8 +286,8 @@ REQUEST_FUNC(mod_vhostdb_handle_docroot) {
if (p->conf.vhostdb_cache && (ve = mod_vhostdb_cache_query(r, p)))
return mod_vhostdb_found(r, ve); /* HANDLER_GO_ON */
b = &p->tmp_buf;
backend = p->conf.vhostdb_backend;
buffer * const b = r->tmp_buf; /*(cleared before use in backend->query())*/
const http_vhostdb_backend_t * const backend = p->conf.vhostdb_backend;
if (0 != backend->query(r, backend->p_d, b)) {
return mod_vhostdb_error_500(r); /* HANDLER_FINISHED */
}

Loading…
Cancel
Save