Re: [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed
On Wed, Nov 07, 2007 at 11:21:30PM +0000, René Scharfe wrote:
Show 20 quoted lines
> Pierre Habouzit schrieb:
> > {
> > const char *percent = strchrnul(fmt, '%');
> > while (*percent) {
> > strbuf_add(sb, fmt, percent - fmt);
> > fmt = percent + 1;
> >
> > /* do your stuff */
> >
> > percent = strchrnul(fmt, '%');
> > }
> > strbuf_add(sb, fmt, percent - fmt);
> > }
> >
> >
> > Which would require strchrnul, but it's trivial compat/ material for sure.
>
> Grepping through the source I see several places that can be simplified
> by converting them to strchrnul(), so I think introducing this GNU
> extension is a good idea in any case. Yes, strchrnul is _very_ useful for parsing.
> Using strchr()/strchrnul() instead of strbuf_addch()'ing is sensible, of
> course. I don't like the duplicate code in your sketch above, though.
> I'll try to look into it later today.
Well you can alternatively write it this way of course:
for (;;) {
const char *percent = strchrnul(fmt, '%');
strbuf_add(sb, fmt, percent - fmt);
if (!*percent)
break /* or return probably */;
fmt = percent + 1; /* do your stuff */
}
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org