httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: Speedup idea (by changing some strcasecmp into memcmp)
Date Tue, 08 Nov 2005 22:44:03 GMT


On 11/08/2005 10:45 PM, Christophe Jaillet wrote:
> Hi,
> 
> in many places in apache, strings are compared using the following
> construction :
>     if (0 == strcasecmp("XX", str)) {
> ...
>     }
>     else if (0 == strcasecmp("YY", str)) {
> ...
>     }
>     else if (0 == strcasecmp("ZZ", str)) {
> ...
>     }
>     else if (0 == strcasecmp("AA", str)) {
> ...
>     }
> ...
> 
> This cascading test could sometimes be optimized by doing the following :
>    * lowercase (or uppercase) a copy of the input string
>    * compare against this modified string using memcmp instead of strcasecmp
> 
> If the idea sounds interesting to you, I can provide a set of patchs that

I guess this depends on the situation and the surrounding code.

1. To actually win cycles the size of the string compared e.g. "AA" in the example
   above and the number of strcasecmp calls need to be large enough. To be honest
   I have no good number at all for "large enough".

2. Is the code that does a copy of this string called many times with the same pool
   without a pool cleanup happening on this pool in the meantime? If yes, depending
   on the number of calls and the size of the string this could waste at lot of memory.

In general I would favour to use strncmp over memcmp in these cases as I want to be
sure that comparison stops once one of the strings actually ends.



Regards

RĂ¼diger


Mime
View raw message