This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #15346] Allow leading and trailing spaces in getdate
- From: Roland McGrath <roland at hack dot frob dot com>
- To: Rich Felker <dalias at aerifal dot cx>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 8 Apr 2013 14:52:57 -0700 (PDT)
- Subject: Re: [PATCH][BZ #15346] Allow leading and trailing spaces in getdate
- References: <20130408125233 dot GS32556 at spoyarek dot pnq dot redhat dot com> <20130408132913 dot GA9017 at domone dot kolej dot mff dot cuni dot cz> <20130408141120 dot GA15689 at spoyarek dot pnq dot redhat dot com> <20130408201256 dot E3C762C09F at topped-with-meat dot com> <20130408212121 dot GS20323 at brightrain dot aerifal dot cx>
> On Mon, Apr 08, 2013 at 01:12:56PM -0700, Roland McGrath wrote:
> > > + /* Skip leading spaces. */
> >
> > s/spaces/whitespace/
> >
> > > + while (string[i] && isspace (string[i]))
> > > + i++;
> >
> > Avoid Boolean coercion: string[i] != '\0'.
> > But since you've already done strlen, why not i < inlen?
>
> I don't think it matters here, but in general the idiom of testing for
> a zero byte is superior to comparing against the length, because it
> involves one fewer variables (and thus less register pressure) in the
> loop.
Fair enough. In this case you're going to do the load regardless, so it's
never saving a load.
But in that case it seems optimal to call strlen on &string[i] after this
loop (or make the loop increment string itself).