diff options
author | ianh <ianh@13f79535-47bb-0310-9956-ffa450edef68> | 2001-11-21 16:40:54 +0000 |
---|---|---|
committer | ianh <ianh@13f79535-47bb-0310-9956-ffa450edef68> | 2001-11-21 16:40:54 +0000 |
commit | 0b4f614e253482f8920aca445acd54aa10441251 (patch) | |
tree | d754badd61e83b20441a7eb464a2b4c5868850ba | |
parent | e53ffb573f4a12da2d2ba79c40207d3c9673898b (diff) | |
download | libapr-0b4f614e253482f8920aca445acd54aa10441251.tar.gz |
This patch speeds up the apr_hash_t implementation's
handling of APR_HASH_KEY_STRING.
The original logic was:
call strlen to get the length of the key;
then iterate through the key to compute the hash;
This patch combines the two into a single pass.
It also changes apr_pool_userdata_get() to take
advantage of this optimization.
Submitted by: Brian Pane <BPane@pacbell.net>
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62535 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | memory/unix/apr_pools.c | 2 | ||||
-rw-r--r-- | tables/apr_hash.c | 16 |
2 files changed, 12 insertions, 6 deletions
diff --git a/memory/unix/apr_pools.c b/memory/unix/apr_pools.c index 5f043f77e..4b5088d2e 100644 --- a/memory/unix/apr_pools.c +++ b/memory/unix/apr_pools.c @@ -1312,7 +1312,7 @@ APR_DECLARE(apr_status_t) apr_pool_userdata_get(void **data, const char *key, ap if (cont->prog_data == NULL) *data = NULL; else - *data = apr_hash_get(cont->prog_data, key, strlen(key)); + *data = apr_hash_get(cont->prog_data, key, APR_HASH_KEY_STRING); return APR_SUCCESS; } diff --git a/tables/apr_hash.c b/tables/apr_hash.c index 8108b580f..18baff85e 100644 --- a/tables/apr_hash.c +++ b/tables/apr_hash.c @@ -222,9 +222,6 @@ static apr_hash_entry_t **find_entry(apr_hash_t *ht, int hash; apr_ssize_t i; - if (klen == APR_HASH_KEY_STRING) - klen = strlen(key); - /* * This is the popular `times 33' hash algorithm which is used by * perl and also appears in Berkeley DB. This is one of the best @@ -263,8 +260,17 @@ static apr_hash_entry_t **find_entry(apr_hash_t *ht, * -- Ralf S. Engelschall <rse@engelschall.com> */ hash = 0; - for (p = key, i = klen; i; i--, p++) - hash = hash * 33 + *p; + if (klen == APR_HASH_KEY_STRING) { + for (p = key; *p; p++) { + hash = hash * 33 + *p; + } + klen = p - (const unsigned char *)key; + } + else { + for (p = key, i = klen; i; i--, p++) { + hash = hash * 33 + *p; + } + } /* scan linked list */ for (hep = &ht->array[hash & ht->max], he = *hep; |