This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add strchrnul


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]