http://issues.apache.org/SpamAssassin/show_bug.cgi?id=4707





------- Additional Comments From [EMAIL PROTECTED]  2005-11-28 05:53 -------
Loren, that's a lot fewer lines of code, but would be slower with the malloc and
free and copying then uppercasing the entire buffer. The buffer can be up to
256K and the string being searched for is likely to be near the beginning.

This code tests at about twice as fast as the existing code. It uses the same
initial search for '\n' that you have, but with memchr because the buffer is not
a c-string. Because we are looking for plain equality of specific ASCII letters,
or-ing with 0x20 can be used and is faster than tolower or using a non-portable
function like memicmp. The search pointer, p, is skipped past characters that we
know are not '\n' before resuming the search.

The existing code is so fast that this discussion probably is not worth having,
even if this is twice as fast :-) My benchmark test of the existing code found
the start of message in t/bsmtp in about a microsecond on my 1.8GHz iMac G5.

 unsigned int i, j, p_len;
 char prev;
 char* p;

 p = m->pre = m->raw;
 while ((p_len = (m->raw_len - (p - m->raw))) > 6) {
   char* q = memchr(p, '\n', p_len - 6);
   if (q == NULL) break;
   if ((((*(++q))|0x20) == 'd') &&
      (((*(q+1))|0x20) == 'a') &&
      (((*(q+2))|0x20) == 't') &&
      (((*(q+3))|0x20) == 'a')) {
    q+=4;
    if (*q == '\r') ++q;
    if (*(q++) == '\n') {
      m->msg = q;
      m->pre_len = q - m->raw;
      m->msg_len = m->raw_len - m->pre_len;
      break;
    }
   }
   p = q+1;
 }

Since it does work and is faster, I think I will check it in if nobody objects.




------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

Reply via email to