httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Laurie <>
Subject Re: Too soon for 1.2 commits ??
Date Wed, 10 Jul 1996 17:15:31 GMT
Robert S. Thau wrote:
>   Ugg. That's horribly inefficient.
> This was in apparent reference to a strcasestr() which worked by doing
> what amounted to str_tolower() on a copy of each string, and then
> doing a plain strstr().  The time taken for this is linear in the
> length of the strings, plus time for the ordinary strstr(), and it's
> not meant to be used in a place which is in the inner loop of anything,
> to the best of my knowledge.

You left out the pstrdup.

> Why is this "horribly inefficient"?  

For two reasons. Firstly, it burns memory. Secondly, I find it unlikely that
a pstrdup followed by 2 strtolowers followed by a strstr is any faster than
simply coding strcasestr standalone.

When measuring the efficiency of a function, the context in which it is used
is immaterial. The context determines the desirability of improving the
efficiency. Furthermore, if you leave a dangerous weapon like a memory-burning
strcasestr lying around, someone less wise than you will use it where it can
really do some damage.



> rst

Ben Laurie                  Phone: +44 (181) 994 6435
Freelance Consultant and    Fax:   +44 (181) 994 6472
Technical Director          Email:
A.L. Digital Ltd,           URL:
London, England.

View raw message