diff: drop line_prefix_length field

The diff_options structure holds a line_prefix string and an associated length. But the length is always just the strlen() of the NUL-terminated string. Let's simplify the code by just storing the string pointer and assuming it is NUL-terminated when we use it. This will cause us to compute the string length in a few extra spots, but I don't think any of these are particularly hot code paths. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 3, 2024 at 17:06 UTC 2011bb4f34d773a7de2d64769ca9f508feba8089
3 files changed +2 -8
diff.c
-1
@@ -5395,7 +5395,6 @@ static int diff_opt_line_prefix(const struct option *opt,
5395
5396 BUG_ON_OPT_NEG(unset);
5397 options->line_prefix = optarg;
5398 - options->line_prefix_length = strlen(options->line_prefix);
5398 graph_setup_line_prefix(options);
5399 return 0;
5400 }
diff.h
-1
@@ -274,7 +274,6 @@ struct diff_options {
274 const char *single_follow;
275 const char *a_prefix, *b_prefix;
276 const char *line_prefix;
277 - size_t line_prefix_length;
277
278 /**
279 * collection of boolean options that affects the operation, but some do
graph.c
+2 -6
@@ -74,10 +74,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
74 if (!diffopt || !diffopt->line_prefix)
75 return;
76
77 - fwrite(diffopt->line_prefix,
78 - sizeof(char),
79 - diffopt->line_prefix_length,
80 - diffopt->file);
77 + fputs(diffopt->line_prefix, diffopt->file);
78 }
79
80 static const char **column_colors;
@@ -321,8 +318,7 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
318
319 strbuf_reset(&msgbuf);
320 if (opt->line_prefix)
324 - strbuf_add(&msgbuf, opt->line_prefix,
325 - opt->line_prefix_length);
321 + strbuf_addstr(&msgbuf, opt->line_prefix);
322 if (graph)
323 graph_padding_line(graph, &msgbuf);
324 return &msgbuf;