From 209d8907319f998f2d10f766bd0bfc4f5db4efcc Mon Sep 17 00:00:00 2001 From: Stefan Fritsch <sf@apache.org> Date: Tue, 18 Jan 2011 09:58:26 +0000 Subject: [PATCH] Initialize the core_dir_config->sec_files and ->sec_if only if needed. This saves some memory and two apr_array_append()s per directory merge. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1060283 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_mmn.h | 3 ++- include/http_core.h | 4 ++-- server/core.c | 26 ++++++++++++++++++-------- server/request.c | 18 ++++++++++++++---- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 097e7c0c1a..ac9b43006e 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -295,7 +295,8 @@ * dynamic growth of balancer members; Remove * BalancerNonce in favor of 'nonce' parameter. * 20110117.0 (2.3.11-dev) Merge <If> sections in separate step (ap_if_walk). - * Add core_dir_config->sec_if. + * Add core_dir_config->sec_if. Add ap_add_if_conf(). + * Add pool argument to ap_add_file_conf(). */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ diff --git a/include/http_core.h b/include/http_core.h index 613148b346..e9df5c826c 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -598,8 +598,8 @@ void ap_core_reorder_directories(apr_pool_t *, server_rec *); /* for mod_perl */ AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config); AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config); -AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config); -AP_CORE_DECLARE(void) ap_add_if_conf(core_dir_config *conf, void *url_config); +AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, void *url_config); +AP_CORE_DECLARE(void) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config); AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg); /* Core filters; not exported. */ diff --git a/server/core.c b/server/core.c index 37d667643e..88cf84b7fd 100644 --- a/server/core.c +++ b/server/core.c @@ -135,12 +135,12 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir) * conf->limit_cpu = NULL; * conf->limit_mem = NULL; * conf->limit_nproc = NULL; + * conf->sec_file = NULL; + * conf->sec_if = NULL; */ conf->limit_req_body = AP_LIMIT_REQ_BODY_UNSET; conf->limit_xml_body = AP_LIMIT_UNSET; - conf->sec_file = apr_array_make(a, 2, sizeof(ap_conf_vector_t *)); - conf->sec_if = apr_array_make(a, 2, sizeof(ap_conf_vector_t *)); conf->server_signature = srv_sig_unset; @@ -513,17 +513,27 @@ AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config) *new_space = url_config; } -AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config) +AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, + void *url_config) { - void **new_space = (void **)apr_array_push(conf->sec_file); + void **new_space; + if (!conf->sec_file) + conf->sec_file = apr_array_make(p, 2, sizeof(ap_conf_vector_t *)); + + new_space = (void **)apr_array_push(conf->sec_file); *new_space = url_config; } -AP_CORE_DECLARE(void) ap_add_if_conf(core_dir_config *conf, void *url_config) +AP_CORE_DECLARE(void) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, + void *url_config) { - void **new_space = (void **)apr_array_push(conf->sec_if); + void **new_space; + + if (!conf->sec_if) + conf->sec_if = apr_array_make(p, 2, sizeof(ap_conf_vector_t *)); + new_space = (void **)apr_array_push(conf->sec_if); *new_space = url_config; } @@ -2032,7 +2042,7 @@ static const char *filesection(cmd_parms *cmd, void *mconfig, const char *arg) conf->d_is_fnmatch = apr_fnmatch_test(conf->d) != 0; conf->r = r; - ap_add_file_conf((core_dir_config *)mconfig, new_file_conf); + ap_add_file_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf); if (*arg != '\0') { return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, @@ -2095,7 +2105,7 @@ static const char *ifsection(cmd_parms *cmd, void *mconfig, const char *arg) conf->d_is_fnmatch = 0; conf->r = NULL; - ap_add_if_conf((core_dir_config *)mconfig, new_file_conf); + ap_add_if_conf(cmd->pool, (core_dir_config *)mconfig, new_file_conf); if (*arg != '\0') { return apr_pstrcat(cmd->pool, "Multiple ", thiscmd->name, diff --git a/server/request.c b/server/request.c index 6b7e891802..fa6d9b7d82 100644 --- a/server/request.c +++ b/server/request.c @@ -1459,12 +1459,17 @@ AP_DECLARE(int) ap_file_walk(request_rec *r) ap_conf_vector_t *now_merged = NULL; core_dir_config *dconf = ap_get_module_config(r->per_dir_config, &core_module); - ap_conf_vector_t **sec_ent = (ap_conf_vector_t **)dconf->sec_file->elts; - int num_sec = dconf->sec_file->nelts; + ap_conf_vector_t **sec_ent = NULL; + int num_sec = 0; walk_cache_t *cache; const char *test_file; int cached; + if (dconf->sec_file) { + sec_ent = (ap_conf_vector_t **)dconf->sec_file->elts; + num_sec = dconf->sec_file->nelts; + } + /* To allow broken modules to proceed, we allow missing filenames to pass. * We will catch it later if it's heading for the core handler. * directory_walk already posted an INFO note for module debugging. @@ -1616,8 +1621,8 @@ AP_DECLARE(int) ap_if_walk(request_rec *r) ap_conf_vector_t *now_merged = NULL; core_dir_config *dconf = ap_get_module_config(r->per_dir_config, &core_module); - ap_conf_vector_t **sec_ent = (ap_conf_vector_t **)dconf->sec_if->elts; - int num_sec = dconf->sec_if->nelts; + ap_conf_vector_t **sec_ent = NULL; + int num_sec = 0; walk_cache_t *cache; int cached; int sec_idx; @@ -1625,6 +1630,11 @@ AP_DECLARE(int) ap_if_walk(request_rec *r) int cached_matches; walk_walked_t *last_walk; + if (dconf->sec_if) { + sec_ent = (ap_conf_vector_t **)dconf->sec_if->elts; + num_sec = dconf->sec_if->nelts; + } + /* No tricks here, there are just no <If > to parse in this context. * We won't destroy the cache, just in case _this_ redirect is later * redirected again to a context containing the same or similar <If >. -- 2.40.0