Re: [PATCH 3/3] pretty=format: Avoid some expensive calculations when not needed
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Nov 6, 2007, 23:45 UTC
- Message-ID
- <Pine.LNX.4.64.0711062343050.4362@racer.site>
- In-Reply-To
- <4730F5FA.3030705@lsrfire.ath.cx>
Hi,
On Wed, 7 Nov 2007, René Scharfe wrote:
Show 5 quoted lines
> By the way, the more intrusive surgery required when using strbuf_expand() > leads to even faster operation. Here my measurements of most of Paul's > test cases (best of three runs): > > [...]
impressive timings. Although I wonder where the time comes from, as the other substitutions should not be _that_ expensive.
In any case, your approach seems much more sensible, now that we have strbuf.
Show 10 quoted lines
> diff --git a/strbuf.h b/strbuf.h
> index cd7f295..95071d5 100644
> --- a/strbuf.h
> +++ b/strbuf.h
> @@ -102,6 +102,9 @@ static inline void strbuf_addbuf(struct strbuf *sb, struct strbuf *sb2) {
> strbuf_add(sb, sb2->buf, sb2->len);
> }
>
> +typedef void (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context);
> +extern void strbuf_expand(struct strbuf *sb, const char *fmt, const char **placeholders, expand_fn_t fn, void *context);I wonder if it would even faster (but maybe not half as readable) if expand_fd_t got the placeholder_index instead of the placeholder.
Ciao, Dscho