On 24 Nov 2015, at 6:36 PM, Yann Ylavic <[email protected]> wrote:
> Sure, but my point is that the worst case is likely depend on the
> application,
It will depend on the application, yes.
> 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")) {
Oops - max-revalidate != must-revalidate
> ...
> }
> else if ...
>
> is going to be costly when matched against "must-revalidate", or worse
> "my-token”.
In that case make it cheaper for those cases.
Have the length handy to check for a minimum-sane-length, then do a switch on
the 4th character.
> We could use all str[n]cmp() first, but still it's a lot of
> comparisons, and now duplicated code too.
The duplicated code is not a worry, the worry is to ensure the most common
cases take the fastest path.
Regards,
Graham
—