diff options
author | Ian Holsman <ianh@apache.org> | 2001-11-21 16:40:54 +0000 |
---|---|---|
committer | Ian Holsman <ianh@apache.org> | 2001-11-21 16:40:54 +0000 |
commit | c267c3899522fb2c89dc8e216dbaaeb70d8fc8f1 (patch) | |
tree | d754badd61e83b20441a7eb464a2b4c5868850ba /tables | |
parent | d0cebae7206800b327344f9c28e4a48e41c5bdfd (diff) | |
download | apr-c267c3899522fb2c89dc8e216dbaaeb70d8fc8f1.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: https://svn.apache.org/repos/asf/apr/apr/trunk@62535 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tables')
-rw-r--r-- | tables/apr_hash.c | 16 |
1 files changed, 11 insertions, 5 deletions
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; |