diff options
author | René Scharfe <l.s.r@web.de> | 2023-01-14 18:03:16 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-01-15 06:22:26 +0300 |
commit | c388fcda9943c0cf46960787041a1ff3bcf5e833 (patch) | |
tree | f7eb4243e00f96a1f353961d9a9121b4b0d325cd /builtin/ls-tree.c | |
parent | 16fb5c54bd91c9714e12c6d742e5a6fd81459b71 (diff) |
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>
Diffstat (limited to 'builtin/ls-tree.c')
-rw-r--r-- | builtin/ls-tree.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index c3284610dd..35e793d4af 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -93,19 +93,16 @@ static size_t expand_show_tree(struct strbuf *sb, const char *start, } else if (skip_prefix(start, "(objectname)", &p)) { strbuf_add_unique_abbrev(sb, data->oid, abbrev); } else if (skip_prefix(start, "(path)", &p)) { - const char *name = data->base->buf; + const char *name; const char *prefix = chomp_prefix ? ls_tree_prefix : NULL; - struct strbuf quoted = STRBUF_INIT; struct strbuf sbuf = STRBUF_INIT; size_t baselen = data->base->len; strbuf_addstr(data->base, data->pathname); name = relative_path(data->base->buf, prefix, &sbuf); - quote_c_style(name, "ed, NULL, 0); + quote_c_style(name, sb, NULL, 0); strbuf_setlen(data->base, baselen); - strbuf_addbuf(sb, "ed); strbuf_release(&sbuf); - strbuf_release("ed); } else { errlen = (unsigned long)len; die(_("bad ls-tree format: %%%.*s"), errlen, start); |