httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yann Ylavic <ylavic....@gmail.com>
Subject Re: svn commit: r1715938 - /httpd/httpd/trunk/modules/cache/cache_util.c
Date Tue, 24 Nov 2015 16:36:58 GMT
On Tue, Nov 24, 2015 at 5:18 PM, Graham Leggett <minfrin@sharp.fm> wrote:
> On 24 Nov 2015, at 6:15 PM, Yann Ylavic <ylavic.dev@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.

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.

Mime
View raw message