httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject Re: Too soon for 1.2 commits ??
Date Wed, 10 Jul 1996 18:20:54 GMT
On Wed, 10 Jul 1996, Ben Laurie wrote:

> 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.

I think I'd tend to agree. There are certainly cases where one can say
"this function sucks eggs, but it's not called very often, and it'd be a
pain to make it efficient". But I don't think this is one of them -
especially not for a simple utility function like this. How about:

char *strcasestr(const char *s1, const char *s2) {
    int len = strlen(s2);

    while (*s1) {
	if (!strncasecmp(s1, s2, len))
	    return s1;
	s1++;
    }
    
    return NULL;
}


-- Alexei Kosut <akosut@organic.com>            The Apache HTTP Server 
   http://www.nueva.pvt.k12.ca.us/~akosut/      http://www.apache.org/


Mime
View raw message