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