summaryrefslogtreecommitdiffstats
path: root/server/provider.c
diff options
context:
space:
mode:
authorChristophe Jaillet <jailletc36@apache.org>2020-11-07 19:59:15 +0100
committerChristophe Jaillet <jailletc36@apache.org>2020-11-07 19:59:15 +0100
commitfb945ce6ec9bd3b29e06c5af4a698a47cb2274f4 (patch)
tree4709cf6659b9c6e8adaf9565acfd57a9bf5c795f /server/provider.c
parentfr doc rebuild. (diff)
downloadapache2-fb945ce6ec9bd3b29e06c5af4a698a47cb2274f4.tar.xz
apache2-fb945ce6ec9bd3b29e06c5af4a698a47cb2274f4.zip
Optimize 'ap_list_provider_names'.
Save some memory and potentialy avoid some useless copy . Using 'goto' is not realy in line with httpd coding style, but the function is small and still readable IMHO. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1883184 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server/provider.c')
-rw-r--r--server/provider.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/server/provider.c b/server/provider.c
index cf307e7c72..f54fb5e36b 100644
--- a/server/provider.c
+++ b/server/provider.c
@@ -55,7 +55,6 @@ AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
provider_group_hash = apr_hash_make(pool);
apr_hash_set(global_providers, provider_group, APR_HASH_KEY_STRING,
provider_group_hash);
-
}
provider_version_hash = apr_hash_get(provider_group_hash, provider_name,
@@ -65,7 +64,6 @@ AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
provider_version_hash = apr_hash_make(pool);
apr_hash_set(provider_group_hash, provider_name, APR_HASH_KEY_STRING,
provider_version_hash);
-
}
/* just set it. no biggy if it was there before. */
@@ -80,7 +78,6 @@ AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
provider_group_hash = apr_hash_make(pool);
apr_hash_set(global_providers_names, provider_group, APR_HASH_KEY_STRING,
provider_group_hash);
-
}
provider_version_hash = apr_hash_get(provider_group_hash, provider_version,
@@ -90,7 +87,6 @@ AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool,
provider_version_hash = apr_hash_make(pool);
apr_hash_set(provider_group_hash, provider_version, APR_HASH_KEY_STRING,
provider_version_hash);
-
}
/* just set it. no biggy if it was there before. */
@@ -132,35 +128,40 @@ AP_DECLARE(apr_array_header_t *) ap_list_provider_names(apr_pool_t *pool,
const char *provider_group,
const char *provider_version)
{
- apr_array_header_t *ret = apr_array_make(pool, 10, sizeof(ap_list_provider_names_t));
+ apr_array_header_t *ret = NULL;
ap_list_provider_names_t *entry;
apr_hash_t *provider_group_hash, *h;
apr_hash_index_t *hi;
char *val;
if (global_providers_names == NULL) {
- return ret;
+ goto out;
}
provider_group_hash = apr_hash_get(global_providers_names, provider_group,
APR_HASH_KEY_STRING);
if (provider_group_hash == NULL) {
- return ret;
+ goto out;
}
- h = apr_hash_get(provider_group_hash, provider_version,
- APR_HASH_KEY_STRING);
+ h = apr_hash_get(provider_group_hash, provider_version, APR_HASH_KEY_STRING);
if (h == NULL) {
- return ret;
+ goto out;
}
+ ret = apr_array_make(pool, apr_hash_count(h), sizeof(ap_list_provider_names_t));
for (hi = apr_hash_first(pool, h); hi; hi = apr_hash_next(hi)) {
apr_hash_this(hi, NULL, NULL, (void *)&val);
entry = apr_array_push(ret);
entry->provider_name = apr_pstrdup(pool, val);
}
+
+out:
+ if (ret == NULL) {
+ ret = apr_array_make(pool, 1, sizeof(ap_list_provider_names_t));
+ }
return ret;
}