Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing
From: Eric Sunshine <hidden>
Date: 2016-06-15 23:00:33
On Wed, Mar 26, 2014 at 7:18 PM, Duy Nguyen [off-list ref] wrote:
On Thu, Mar 27, 2014 at 2:22 AM, Eric Sunshine [off-list ref] wrote:quoted
quoted
static void show_dir_entry(const char *tag, struct dir_entry *ent) { + static struct strbuf sb = STRBUF_INIT; int len = max_prefix_len; if (len >= ent->len)@@ -67,8 +79,10 @@ static void show_dir_entry(const char *tag, struct dir_entry *ent) if (!dir_path_match(ent, &pathspec, len, ps_matched)) return; - fputs(tag, stdout); - write_name(ent->name); + strbuf_reset(&sb); + strbuf_addstr(&sb, tag); + write_name(&sb, ent->name); + strbuf_fputs(&sb, stdout);strbuf_release(&sb);Not strictly necessary because sb is static and will be reset at the next call. I just want to lower the number of allocation (write_name allocates some more). It may be a premature optimization though.
Ah, yes. I noted the 'static' on my initial read-through but had forgotten about it by the time I finally got to a computer with which I could send plain-text email. Sorry for the noise.
The same for changes in show_ce_entry(). -- Duy