From: Pierre Habouzit <madcoder@debian.org>
To: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
"Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
git@vger.kernel.org
Subject: Re: [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed
Date: Wed, 07 Nov 2007 01:14:58 +0100 [thread overview]
Message-ID: <20071107001458.GE4382@artemis.corp> (raw)
In-Reply-To: <20071107001112.GD4382@artemis.corp>
[-- Attachment #1: Type: text/plain, Size: 2070 bytes --]
On Wed, Nov 07, 2007 at 12:11:12AM +0000, Pierre Habouzit wrote:
> On Tue, Nov 06, 2007 at 11:17:14PM +0000, René Scharfe wrote:
> > I haven't seen any comments on strbuf_expand. Is it too far out?
> > Here it is again, adjusted for current master and with the changes
> > to strbuf.[ch] coming first:
>
> I have one.
>
> > strbuf.c | 22 +++++
> > strbuf.h | 3
> > pretty.c | 276 ++++++++++++++++++++++++++++++++++-----------------------------
> > 3 files changed, 178 insertions(+), 123 deletions(-)
> >
> > diff --git a/strbuf.c b/strbuf.c
> > index f4201e1..b71da99 100644
> > --- a/strbuf.c
> > +++ b/strbuf.c
> > @@ -129,6 +129,28 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
> > strbuf_setlen(sb, sb->len + len);
> > }
> >
> > +void strbuf_expand(struct strbuf *sb, const char *fmt,
> > + const char **placeholders, expand_fn_t fn, void *context)
> > +{
> > + char c;
> > + const char **p;
> > +
> > + while ((c = *fmt++)) {
> > + if (c != '%') {
> > + strbuf_addch(sb, c);
> > + continue;
> > + }
>
> strbuf_addch is pretty inneficient as it puts NULs each time. rather
> do that (sketchy) :
>
> {
> for (;;) {
> const char *percent = strchr(fmt, '%');
> if (!percent)
> break;
> strbuf_add(sb, fmt, percent - fmt);
> fmt = percent + 1;
>
> /* do your stuff */
> }
> strbuf_addstr(sb, fmt);
> }
Or if we are at this level of micro-optimization:
{
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.
--
·O· Pierre Habouzit
··O madcoder@debian.org
OOO http://www.madism.org
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-11-07 0:15 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-04 19:14 [PATCH 0/3] Make user formatted commit listing less expensive Johannes Schindelin
2007-11-04 19:15 ` [PATCH 1/3] Split off the pretty print stuff into its own file Johannes Schindelin
2007-11-05 21:16 ` Junio C Hamano
2007-11-04 19:15 ` [PATCH 2/3] interpolate.[ch]: Add a function to find which interpolations are active Johannes Schindelin
2007-11-04 19:15 ` [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed Johannes Schindelin
2007-11-05 19:51 ` Junio C Hamano
2007-11-05 20:21 ` René Scharfe
2007-11-05 20:25 ` Jon Loeliger
2007-11-05 23:53 ` Johannes Schindelin
2007-11-06 1:06 ` Junio C Hamano
2007-11-06 22:31 ` René Scharfe
2007-11-06 23:17 ` René Scharfe
2007-11-06 23:45 ` Johannes Schindelin
2007-11-07 23:19 ` René Scharfe
2007-11-08 0:14 ` Johannes Schindelin
2007-11-07 0:11 ` Pierre Habouzit
2007-11-07 0:14 ` Pierre Habouzit [this message]
2007-11-07 23:21 ` René Scharfe
2007-11-07 23:31 ` Pierre Habouzit
2007-11-07 20:43 ` Junio C Hamano
2007-11-09 0:49 ` René Scharfe
2007-11-06 23:36 ` Johannes Schindelin
2007-11-06 23:38 ` [PATCH 1/2] interpolate.[ch]: Add a function to find which interpolations are active Johannes Schindelin
2007-11-06 23:38 ` [PATCH 2/2] pretty=format: Avoid some expensive calculations when not needed Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071107001458.GE4382@artemis.corp \
--to=madcoder@debian.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=rene.scharfe@lsrfire.ath.cx \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.