No matter how much you may optimize at the *C* level, I doubt that you'll
match what various C libraries will do. Anybody worth their salt would code
strchr() in assembly (and fall back to a C implementation if there isn't a
selected ASM version for the host platform).
Then, you have the whole "compiler can detect strchr()" aspect. I believe
that GCC recognizes it. ... Yup. I see an ASM version on my system.
btw, function open/close braces are *always* at column zero in Apache code.
Most other style stuff can be flexed, but not that one. :-)
Cheers,
-g
On Wed, May 23, 2001 at 07:55:06PM -0400, Greg Marr wrote:
> At 06:33 PM 05/23/2001, Greg Stein wrote:
> >And we *should* use strchr(). Unwrapping that into a loop is bogus.
> >Even if
> >the compiler doesn't optimize it, the C library has highly optimized
> >versions which isn't going to happen with our own implementation.
>
> Since I was curious, I went looking for one:
>
> char * strchr (
> const char * string,
> int ch
> )
> {
> while (*string && *string != (char)ch)
> string++;
>
> if (*string == (char)ch)
> return((char *)string);
> return(NULL);
> }
>
> Well, it's somewhat optimized, but not quite how I would have written
> it, and it's horribly formatted.
>
> char * strchr(const char *string, int ch)
> {
> while(*string && (*string != (char)ch))
> string++;
>
> return(*string ? (char *)string : NULL);
> }
>
> Ah, much better.
>
> --
> Greg Marr
> [EMAIL PROTECTED]
> "We thought you were dead."
> "I was, but I'm better now." - Sheridan, "The Summoning"
--
Greg Stein, http://www.lyra.org/