Skip to content

Commit c388fcd

Browse files
rscharfegitster
authored andcommitted
ls-tree: remove dead store and strbuf for quote_c_style()
Stop initializing "name" because it is set again before use. Let quote_c_style() write directly to "sb" instead of taking a detour through "quoted". This avoids an allocation and a string copy. The result is the same because the function only appends. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16fb5c5 commit c388fcd

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

builtin/ls-tree.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,16 @@ static size_t expand_show_tree(struct strbuf *sb, const char *start,
9393
} else if (skip_prefix(start, "(objectname)", &p)) {
9494
strbuf_add_unique_abbrev(sb, data->oid, abbrev);
9595
} else if (skip_prefix(start, "(path)", &p)) {
96-
const char *name = data->base->buf;
96+
const char *name;
9797
const char *prefix = chomp_prefix ? ls_tree_prefix : NULL;
98-
struct strbuf quoted = STRBUF_INIT;
9998
struct strbuf sbuf = STRBUF_INIT;
10099
size_t baselen = data->base->len;
101100

102101
strbuf_addstr(data->base, data->pathname);
103102
name = relative_path(data->base->buf, prefix, &sbuf);
104-
quote_c_style(name, &quoted, NULL, 0);
103+
quote_c_style(name, sb, NULL, 0);
105104
strbuf_setlen(data->base, baselen);
106-
strbuf_addbuf(sb, &quoted);
107105
strbuf_release(&sbuf);
108-
strbuf_release(&quoted);
109106
} else {
110107
errlen = (unsigned long)len;
111108
die(_("bad ls-tree format: %%%.*s"), errlen, start);

0 commit comments

Comments
 (0)