summaryrefslogtreecommitdiff
path: root/tables
diff options
context:
space:
mode:
authorianh <ianh@13f79535-47bb-0310-9956-ffa450edef68>2001-11-21 16:40:54 +0000
committerianh <ianh@13f79535-47bb-0310-9956-ffa450edef68>2001-11-21 16:40:54 +0000
commit0b4f614e253482f8920aca445acd54aa10441251 (patch)
treed754badd61e83b20441a7eb464a2b4c5868850ba /tables
parente53ffb573f4a12da2d2ba79c40207d3c9673898b (diff)
downloadlibapr-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
Diffstat (limited to 'tables')
-rw-r--r--tables/apr_hash.c16
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;