From: Jeff King Date: Thu, 3 Oct 2024 21:11:31 +0000 (-0400) Subject: diff: return line_prefix directly when possible X-Git-Tag: v2.47.1~10^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=19752d9c912478b9eef0bd83c2cf6da98974f536;p=thirdparty%2Fgit.git diff: return line_prefix directly when possible We may point our output_prefix callback to diff_output_prefix_callback() in any of these cases: 1. we have a user-provided line_prefix 2. we have a graph prefix to show 3. both (1) and (2) The function combines the available elements into a strbuf and returns its pointer. In the case that we just have the line_prefix, though, there is no need for the strbuf. We can return the string directly. This is a minor optimization by itself, but also will allow us to clean up some memory ownership issues on top. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/graph.c b/graph.c index 6a4db229bb..c8833ecc3e 100644 --- a/graph.c +++ b/graph.c @@ -316,6 +316,9 @@ static const char *diff_output_prefix_callback(struct diff_options *opt, void *d assert(opt); + if (!graph) + return opt->line_prefix; + strbuf_reset(&msgbuf); if (opt->line_prefix) strbuf_addstr(&msgbuf, opt->line_prefix);