ianh 01/11/21 08:40:54
Modified: memory/unix apr_pools.c
tables apr_hash.c
Log:
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 <[EMAIL PROTECTED]>
Revision Changes Path
1.116 +1 -1 apr/memory/unix/apr_pools.c
Index: apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -r1.115 -r1.116
--- apr_pools.c 2001/10/29 14:54:19 1.115
+++ apr_pools.c 2001/11/21 16:40:54 1.116
@@ -1312,7 +1312,7 @@
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;
}
1.28 +11 -5 apr/tables/apr_hash.c
Index: apr_hash.c
===================================================================
RCS file: /home/cvs/apr/tables/apr_hash.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- apr_hash.c 2001/11/10 17:58:36 1.27
+++ apr_hash.c 2001/11/21 16:40:54 1.28
@@ -222,9 +222,6 @@
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 @@
* -- Ralf S. Engelschall <[EMAIL PROTECTED]>
*/
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;