apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Holsman <i...@cnet.com>
Subject Re: [PATCH] optimization for hash tables and pool userdata
Date Wed, 21 Nov 2001 17:03:23 GMT
On Sat, 2001-11-17 at 23:35, Brian Pane wrote:
> 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.
> 
> --Brian
> 
Commited
Thanks Brian
> 
> ----
> 

> Index: srclib/apr/tables/apr_hash.c
> ===================================================================
> RCS file: /home/cvspublic/apr/tables/apr_hash.c,v
> retrieving revision 1.27
> diff -u -r1.27 apr_hash.c
> --- srclib/apr/tables/apr_hash.c	2001/11/10 17:58:36	1.27
> +++ srclib/apr/tables/apr_hash.c	2001/11/18 07:16:32
> @@ -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 <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;
> Index: srclib/apr/memory/unix/apr_pools.c
> ===================================================================
> RCS file: /home/cvspublic/apr/memory/unix/apr_pools.c,v
> retrieving revision 1.115
> diff -u -r1.115 apr_pools.c
> --- srclib/apr/memory/unix/apr_pools.c	2001/10/29 14:54:19	1.115
> +++ srclib/apr/memory/unix/apr_pools.c	2001/11/18 07:16:33
> @@ -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;
>  }
>  
-- 
Ian Holsman          IanH@cnet.com
Performance Measurement & Analysis
CNET Networks   -   (415) 344-2608


Mime
View raw message