tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/common jk_map.c
Date Fri, 18 Oct 2002 11:45:25 GMT
mturk       2002/10/18 04:45:25

  Modified:    jk/native2/common jk_map.c
  Log:
  Add the key checksum processing from APR table.
  This speeds up the get/put table operations a lot.
  
  Revision  Changes    Path
  1.22      +61 -5     jakarta-tomcat-connectors/jk/native2/common/jk_map.c
  
  Index: jk_map.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_map.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- jk_map.c	10 Jun 2002 21:55:06 -0000	1.21
  +++ jk_map.c	18 Oct 2002 11:45:25 -0000	1.22
  @@ -72,23 +72,63 @@
   typedef struct jk_map_private {
       char **names;
       void **values;
  +    apr_uint32_t  *keys;
   
       int capacity;
       int size;
   } jk_map_private_t;
   
  +#if APR_CHARSET_EBCDIC
  +#define CASE_MASK 0xbfbfbfbf
  +#else
  +#define CASE_MASK 0xdfdfdfdf
  +#endif
  +
  +/* Compute the "checksum" for a key, consisting of the first
  + * 4 bytes, normalized for case-insensitivity and packed into
  + * an int...this checksum allows us to do a single integer
  + * comparison as a fast check to determine whether we can
  + * skip a strcasecmp
  + */
  +#define COMPUTE_KEY_CHECKSUM(key, checksum)    \
  +{                                              \
  +    const char *k = (key);                     \
  +    apr_uint32_t c = (apr_uint32_t)*k;         \
  +    (checksum) = c;                            \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (apr_uint32_t)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (apr_uint32_t)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (apr_uint32_t)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    checksum &= CASE_MASK;                     \
  +}
  +
   static void *jk2_map_default_get(jk_env_t *env, jk_map_t *m,
                                    const char *name)
   {
       int i;
       jk_map_private_t *mPriv;
  -    
  +    apr_uint32_t checksum;
  +
       if(name==NULL )
           return NULL;
       mPriv=(jk_map_private_t *)m->_private;
   
  +    COMPUTE_KEY_CHECKSUM(name, checksum);
  +
       for(i = 0 ; i < mPriv->size ; i++) {
  -        if(0 == strcmp(mPriv->names[i], name)) {
  +        if (mPriv->keys[i] == checksum && 
  +            strcmp(mPriv->names[i], name) == 0) {
               /*fprintf(stderr, "jk_map.get found %s %s \n", name, mPriv->values[i]  );
*/
               return  mPriv->values[i];
           }
  @@ -105,6 +145,7 @@
       if(mPriv->size >= mPriv->capacity) {
           char **names;
           void **values;
  +        apr_uint32_t *keys;
           int  capacity = mPriv->capacity + CAPACITY_INC_SIZE;
   
           names = (char **)m->pool->calloc(env, m->pool,
  @@ -112,7 +153,9 @@
           values = (void **)m->pool->calloc(env, m->pool,
                                            sizeof(void *) * capacity);
   
  -        if( names== NULL || values==NULL ) {
  +        keys = (apr_uint32_t *)m->pool->calloc(env, m->pool,
  +                                                 sizeof(apr_uint32_t) * capacity);
  +        if( names== NULL || values==NULL || keys==NULL) {
               env->l->jkLog(env, env->l, JK_LOG_ERROR,
                             "map.realloc(): AllocationError\n");
               return JK_ERR;
  @@ -125,9 +168,13 @@
           
           if (mPriv->capacity && mPriv->values)
               memcpy(values, mPriv->values, sizeof(void *) * mPriv->capacity);
  +
  +        if (mPriv->capacity && mPriv->keys)
  +            memcpy(keys, mPriv->keys, sizeof(apr_uint32_t) * mPriv->capacity);
           
           mPriv->names = ( char **)names;
           mPriv->values = ( void **)values;
  +        mPriv->keys = keys;
           mPriv->capacity = capacity;
           
           return JK_OK;
  @@ -144,14 +191,18 @@
       int rc = JK_ERR;
       int i;
       jk_map_private_t *mPriv;
  +    apr_uint32_t checksum;
   
       if( name==NULL ) 
           return JK_ERR;
   
       mPriv=(jk_map_private_t *)m->_private;
       
  +    COMPUTE_KEY_CHECKSUM(name, checksum);
  +
       for(i = 0 ; i < mPriv->size ; i++) {
  -        if(0 == strcmp(mPriv->names[i], name)) {
  +        if (mPriv->keys[i] == checksum && 
  +            strcmp(mPriv->names[i], name) == 0) {
               break;
           }
       }
  @@ -175,6 +226,7 @@
           mPriv->names[mPriv->size] =  (char *)name; 
           */
           mPriv->names[mPriv->size] = m->pool->pstrdup(env,m->pool, name);
  +        mPriv->keys[mPriv->size] = checksum;
           mPriv->size ++;
           rc = JK_OK;
       }
  @@ -195,6 +247,9 @@
       jk2_map_default_realloc(env, m);
       
       if(mPriv->size < mPriv->capacity) {
  +        apr_uint32_t checksum;
  +    
  +        COMPUTE_KEY_CHECKSUM(name, checksum);
           mPriv->values[mPriv->size] = value;
           /* XXX this is wrong - either we take ownership and copy both
              name and value,
  @@ -202,6 +257,7 @@
           */
           /*     mPriv->names[mPriv->size] = m->pool->pstrdup(m->pool, name);
*/
           mPriv->names[mPriv->size] =  (char *)name; 
  +        mPriv->keys[mPriv->size] = checksum;
           mPriv->size ++;
           rc = JK_OK;
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message