Cliff Woolley wrote:

On Sat, 17 Nov 2001, Brian Pane wrote:

This patch adds a cache to each element in an apr_table_t.
The cache consists of a 32-bit int containing the first 4 bytes
of the element's key, converted to uppercase.


How about something like this:

#ifndef EBCDIC
#define CASE_MASK 0xdfdfdfdf
#else
#define CASE_MASK 0x0 /* whatever this is supposed to be */
#endif

#define COMPUTE_KEY_PREFIX(key, prefix)         \
{                                               \
   if (key[0] && key[1] && key[2] && key[3]) { \
       prefix = (*((int *)(key))) & CASE_MASK; \
   }                                           \
   else {                                      \
       prefix = 0;                             \
   }                                           \


The only problem with this is that the bytes in the integer end up "backwards" on little-endian machines. That means that, while you can check for equality on the prefix, you can't do greater-than/less-than comparisons.

I used the more complicated, shift-based approach because it
guarantees that greater-than/less-than comparisons on the prefix
will yield the same results as strcasecmp on the first 4 bytes.
This makes it possible to use the prefix in the comparator
function in the big qsort in apr_table_overlap, which does
a *lot* of strcasecmp calls otherwise.

--Brian





Reply via email to