httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Closing strcasestr discussion...
Date Fri, 12 Jul 1996 15:09:05 GMT
> That's a point I brought up, but in actual testing there was again zero
> difference between this particular method and the method where it uses
> strncasecmp on the entire s1 string.  I would tend to believe that the
> first thing str[ncase]cmp does is make sure that the string sizes match?
> At least possibly in the gnu libs.  Like I said, I'm going to have to
> go look at the actual implementation of strncasecmp() to see exactly
> what they are doing in the libs.

I posted a strncasecmp() implementation yesterday.  I believe it is from
the BSD libs.  The relevant part is:

int strncasecmp(char *s1, char *s2, register int n) {
    register u_char *cm = charmap,
            *us1 = (u_char *)s1,
            *us2 = (u_char *)s2;

    while(--n >= 0 && cm[*us1] == cm[*us2++])
        if(*us1++ == '\0')
    return(n < 0 ? 0 : cm[*us1] - cm[*--us2]);

So no, it doesn't check the length first.  But, as soon as the end of
either string is hit, the while loop will terminate, so it only ever
loops for the length of the shorter of the two arguments.  If you can
make either argument shorter, then you will decrease the number of iterations.


View raw message