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@xxxxxxxx> --- diff.c | 1 - diff.h | 1 - graph.c | 8 ++------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/diff.c b/diff.c index 173cbe2bed..858e001993 100644 --- a/diff.c +++ b/diff.c @@ -5400,7 +5400,6 @@ static int diff_opt_line_prefix(const struct option *opt, BUG_ON_OPT_NEG(unset); options->line_prefix = optarg; - options->line_prefix_length = strlen(options->line_prefix); graph_setup_line_prefix(options); return 0; } diff --git a/diff.h b/diff.h index 0cde3b34e2..ea3634106d 100644 --- a/diff.h +++ b/diff.h @@ -274,7 +274,6 @@ struct diff_options { const char *single_follow; const char *a_prefix, *b_prefix; const char *line_prefix; - size_t line_prefix_length; /** * collection of boolean options that affects the operation, but some do diff --git a/graph.c b/graph.c index 091c14cf4f..2cee47294f 100644 --- a/graph.c +++ b/graph.c @@ -76,10 +76,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt) if (!diffopt || !diffopt->line_prefix) return; - fwrite(diffopt->line_prefix, - sizeof(char), - diffopt->line_prefix_length, - diffopt->file); + fputs(diffopt->line_prefix, diffopt->file); } static const char **column_colors; @@ -323,8 +320,7 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void strbuf_reset(&msgbuf); if (opt->line_prefix) - strbuf_add(&msgbuf, opt->line_prefix, - opt->line_prefix_length); + strbuf_addstr(&msgbuf, opt->line_prefix); if (graph) graph_padding_line(graph, &msgbuf); return &msgbuf; -- 2.47.0.rc1.384.g9f398d04fd