mturk       2004/11/29 07:55:27

  Modified:    jk/native/common jk_map.c
  Log:
  Backport checksum_key calculation for map properties for speeading
  up finding map key/value pairs.
  
  Revision  Changes    Path
  1.21      +75 -12    jakarta-tomcat-connectors/jk/native/common/jk_map.c
  
  Index: jk_map.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_map.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- jk_map.c  19 Nov 2004 14:28:57 -0000      1.20
  +++ jk_map.c  29 Nov 2004 15:55:27 -0000      1.21
  @@ -33,6 +33,41 @@
   #define CAPACITY_INC_SIZE (50)
   #define LENGTH_OF_LINE    (1024)
   
  +#ifdef AS400
  +#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);                     \
  +    unsigned int c = (unsigned int)*k;         \
  +    (checksum) = c;                            \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (unsigned int)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (unsigned int)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    (checksum) <<= 8;                          \
  +    if (c) {                                   \
  +        c = (unsigned int)*++k;                \
  +        checksum |= c;                         \
  +    }                                          \
  +    checksum &= CASE_MASK;                     \
  +}
  +
   struct jk_map
   {
       jk_pool_t p;
  @@ -40,9 +75,10 @@
   
       const char **names;
       const void **values;
  +    unsigned int *keys;
   
  -    unsigned capacity;
  -    unsigned size;
  +    unsigned int capacity;
  +    unsigned int size;
   };
   
   static void trim_prp_comment(char *prp);
  @@ -79,6 +115,7 @@
           jk_open_pool(&m->p, m->buf, sizeof(jk_pool_atom_t) * 
SMALL_POOL_SIZE);
           m->capacity = 0;
           m->size = 0;
  +        m->keys  = NULL;
           m->names = NULL;
           m->values = NULL;
           rc = JK_TRUE;
  @@ -104,9 +141,11 @@
       const void *rc = (void *)def;
   
       if (m && name) {
  -        unsigned i;
  +        unsigned int i;
  +        unsigned int key;
  +        COMPUTE_KEY_CHECKSUM(name, key)
           for (i = 0; i < m->size; i++) {
  -            if (0 == strcmp(m->names[i], name)) {
  +            if (m->keys[i] == key && strcmp(m->names[i], name) == 0) {
                   rc = m->values[i];
                   break;
               }
  @@ -116,6 +155,26 @@
       return (void *)rc;          /* DIRTY */
   }
   
  +char *jk_map_get_string(jk_map_t *m, const char *name, const char *def)
  +{
  +    char *rc = (char *)def;
  +
  +    if (m && name) {
  +        unsigned int i;
  +        unsigned int key;
  +        COMPUTE_KEY_CHECKSUM(name, key)
  +        for (i = 0; i < m->size; i++) {
  +            if (m->keys[i] == key && strcmp(m->names[i], name) == 0) {
  +                rc = (char *)m->values[i];
  +                break;
  +            }
  +        }
  +    }
  +
  +    return rc;
  +}
  +
  +
   int jk_map_get_int(jk_map_t *m, const char *name, int def)
   {
       char buf[100];
  @@ -176,11 +235,6 @@
       return rv;
   }
   
  -char *jk_map_get_string(jk_map_t *m, const char *name, const char *def)
  -{
  -    return jk_map_get(m, name, def);
  -}
  -
   char **jk_map_get_string_list(jk_map_t *m,
                                 const char *name,
                                 unsigned *list_len, const char *def)
  @@ -239,9 +293,11 @@
       int rc = JK_FALSE;
   
       if (m && name && old) {
  -        unsigned i;
  +        unsigned int i;
  +        unsigned int key;
  +        COMPUTE_KEY_CHECKSUM(name, key)
           for (i = 0; i < m->size; i++) {
  -            if (0 == strcmp(m->names[i], name)) {
  +            if (m->keys[i] == key && strcmp(m->names[i], name) == 0) {
                   break;
               }
           }
  @@ -257,6 +313,7 @@
               if (m->size < m->capacity) {
                   m->values[m->size] = value;
                   m->names[m->size] = jk_pool_strdup(&m->p, name);
  +                m->keys[m->size] = key;
                   m->size++;
                   rc = JK_TRUE;
               }
  @@ -411,10 +468,12 @@
       if (m->size == m->capacity) {
           char **names;
           void **values;
  +        unsigned int *keys;
           int capacity = m->capacity + CAPACITY_INC_SIZE;
   
           names = (char **)jk_pool_alloc(&m->p, sizeof(char *) * capacity);
           values = (void **)jk_pool_alloc(&m->p, sizeof(void *) * capacity);
  +        keys = (unsigned int *)jk_pool_alloc(&m->p, sizeof(unsigned int) * 
capacity);
   
           if (values && names) {
               if (m->capacity && m->names)
  @@ -423,8 +482,12 @@
               if (m->capacity && m->values)
                   memcpy(values, m->values, sizeof(void *) * m->capacity);
   
  +            if (m->capacity && m->keys)
  +                memcpy(keys, m->keys, sizeof(unsigned int) * m->capacity);
  +
               m->names = (const char **)names;
               m->values = (const void **)values;
  +            m->keys = keys;
               m->capacity = capacity;
   
               return JK_TRUE;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to