On Tue, Nov 24, 2015 at 5:18 PM, Graham Leggett <[email protected]> wrote:
> On 24 Nov 2015, at 6:15 PM, Yann Ylavic <[email protected]> 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.
Sure, but my point is that the worst case is likely depend on the
application, eg:
case 'm':
case 'M':
if (!strncmp(token, "max-age", 7)
|| !ap_casecmpstrn(token, "max-age", 7)) {
...
}
else if (!strncmp(token, "max-stale", 9)
|| !ap_casecmpstrn(token, "max-stale", 9)) {
...
}
else if (!strncmp(token, "min-fresh", 9)
|| !ap_casecmpstrn(token, "min-fresh", 9)) {
...
}
else if (!strcmp(token, "max-revalidate")
|| !ap_casecmpstr(token, "must-revalidate")) {
...
}
else if ...
is going to be costly when matched against "must-revalidate", or worse
"my-token".
We could use all str[n]cmp() first, but still it's a lot of
comparisons, and now duplicated code too.
Regards,
Yann.