[PATCH] Add strchrnul

Corinna Vinschen vinschen@redhat.com
Mon Mar 28 10:12:00 GMT 2011


Hi Yaakov,

On Mar 27 22:37, Yaakov (Cygwin/X) wrote:
> char *
> _DEFUN (strchrnul, (s1, i),
> 	_CONST char *s1 _AND
> 	int i)
> {
>   char *s = strchr(s1, i);
> 
>   if (*s != NULL)
>     return s;
>   return (char *)s1 + strlen(s1);
> }

Isn't this implementation a bit simple?  It's as fast as the underlying
strchr function in case of a hit, but it suffers quite a performance hit
in case of a miss, because the string has to be scanned twice.

So I'm wondering, shouldn't we better adapt the strchr implementation
and just return a pointer to s where strchr returns NULL?


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat



More information about the Newlib mailing list