On Tue, Nov 24, 2015 at 12:03 PM, Jim Jagielski <j...@jagunet.com> wrote:
> > > On Nov 24, 2015, at 11:18 AM, Graham Leggett <minf...@sharp.fm> wrote: > > > > On 24 Nov 2015, at 6:15 PM, Yann Ylavic <ylavic....@gmail.com> wrote: > > > >> Not sure: > >> if (!strcmp(h, "max-age") > >> || ap_cmpcasestr(h, "max-age")) > >> is likely to be a bit faster than a single ap_cmpcasestr() when it > >> matches, but much slower when it does not. > > > > Yep, that’s the point. > > > > The vast majority of comparisons are lowercase for tokens like this. > Might as well test that fast path first before testing the worst case > scenario. > > > > Is there REALLY that much of a diff between > > if (ucharmap[*ps1] != ucharmap[*ps2]) { > > and > > if (*ps1 != *ps2) { > > to muddle up the code like that though?? > I'm wondering the other way around. Even in Yann's latest exercise, simply testing if ((*ps1 == *ps2) || (ucharmap[*ps1] != ucharmap[*ps2])) { (or in Yann's code, use the const int lookups, considering that they should be optimized out by the compiler if the first pattern matches). Really we are expecting one of two things in strcmp_token(), we will usually have an all-samecase (e.g. "GET" or "upgrade") and the exceptions will largely be proper-case (e.g. "Upgrade"). So doing the first char case-insensitively always seems smart and then falling back on casematch until we don't case match. By the time we've coded all that up, I wonder what the performance is when simply checking equality and then the lookup match on the character-by-character basis, for mixed vs Mixed vs MIXED.