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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 14, 2023 at 16:03 UTC
c388fcda9943c0cf46960787041a1ff3bcf5e833
1 file changed
+2
-5
builtin/ls-tree.c
+2
-5
@@ -93,19 +93,16 @@ static size_t expand_show_tree(struct strbuf *sb, const char *start,
93
} else if (skip_prefix(start, "(objectname)", &p)) {
94
strbuf_add_unique_abbrev(sb, data->oid, abbrev);
95
} else if (skip_prefix(start, "(path)", &p)) {
96
- const char *name = data->base->buf;
96
+ const char *name;
97
const char *prefix = chomp_prefix ? ls_tree_prefix : NULL;
98
- struct strbuf quoted = STRBUF_INIT;
98
struct strbuf sbuf = STRBUF_INIT;
99
size_t baselen = data->base->len;
100
101
strbuf_addstr(data->base, data->pathname);
102
name = relative_path(data->base->buf, prefix, &sbuf);
104
- quote_c_style(name, "ed, NULL, 0);
103
+ quote_c_style(name, sb, NULL, 0);
104
strbuf_setlen(data->base, baselen);
106
- strbuf_addbuf(sb, "ed);
105
strbuf_release(&sbuf);
108
- strbuf_release("ed);
106
} else {
107
errlen = (unsigned long)len;
108
die(_("bad ls-tree format: %%%.*s"), errlen, start);