This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH] Add strchrnul
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Mon, 28 Mar 2011 10:10:42 +0200
- Subject: Re: [PATCH] Add strchrnul
- References: <1301283467.5408.7.camel@YAAKOV04>
- Reply-to: newlib at sourceware dot org
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