Thread (65 messages) flat view 65 messages, 4 authors, 2016-06-15

Re: [PATCH v2 05/17] ls-files: buffer full item in strbuf before printing

From: Duy Nguyen <hidden>
Date: 2016-06-15 23:00:33

On Thu, Mar 27, 2014 at 2:22 AM, Eric Sunshine [off-list ref] wrote:
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.

The same for changes in show_ce_entry().
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help