apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Marr <gr...@alum.wpi.edu>
Subject Re: cvs commit: apr/test teststr.c .cvsignore Makefile.in
Date Wed, 23 May 2001 23:55:06 GMT
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
gregm@alum.wpi.edu
"We thought you were dead."
"I was, but I'm better now." - Sheridan, "The Summoning"


Mime
View raw message