Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 27, 2014, 05:22 UTC
- Message-ID
- <CAPig+cQ5amNNUh4XHp=tJh8BWpTASThPOB-750SzAdUi3Q1Dzw@mail.gmail.com>
- In-Reply-To
- <CACsJy8B653BGo8GEBv1VFMZ1ncEeYXFqY5KcR-4thv9hk2+ApA@mail.gmail.com>
On Wed, Mar 26, 2014 at 7:18 PM, Duy Nguyen <pclouds@gmail.com> wrote:
Show 23 quoted lines
> On Thu, Mar 27, 2014 at 2:22 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>> 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