libc/string/strrchr.c
J. Johnston
jjohnstn@cygnus.com
Fri May 4 10:26:00 GMT 2001
Earnie Boyd wrote:
>
> "J. Johnston" wrote:
> >
> > Earnie Boyd wrote:
> > >
> > > This patch improves Cygwin's speed greatly.
> > >
> > > Earnie.
> > >
> >
> > Your patch needs a special case for the null terminator. Both strchr and strrchr treat the null
> > terminator as part of the string and allow searches for it. In your loop, the null terminator can
> > be found by strchr() but then you will increment s and will start searching beyond the end of the
> > string.
> >
>
> Ok, good catch. How about this one.
>
That solved it. Patch checked in. Thanks.
-- Jeff J.
> ----------------------------------------------------------------------------------------------------
> 2001-05-04 Earnie Boyd <earnie@users.sourceforge.net>
>
> * libc/string/strrchr.c: Use strchr for the speed improvements.
>
> Index: strrchr.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/string/strrchr.c,v
> retrieving revision 1.1.1.1
> diff -u -p -r1.1.1.1 strrchr.c
> --- strrchr.c 2000/02/17 19:39:48 1.1.1.1
> +++ strrchr.c 2001/05/04 12:25:57
> @@ -41,21 +41,19 @@ _DEFUN (strrchr, (s, i),
> int i)
> {
> _CONST char *last = NULL;
> - char c = i;
>
> - while (*s)
> + if (i)
> {
> - if (*s == c)
> + while (s=strchr(s, i))
> {
> last = s;
> + s++;
> }
> - s++;
> }
> -
> - if (*s == c)
> + else
> {
> - last = s;
> + last = strchr(s, i);
> }
> -
> +
> return (char *) last;
> }
More information about the Newlib
mailing list