Skip to content

Commit 2011bb4

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8aeff2c commit 2011bb4

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

diff.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5395,7 +5395,6 @@ static int diff_opt_line_prefix(const struct option *opt,
53955395

53965396
BUG_ON_OPT_NEG(unset);
53975397
options->line_prefix = optarg;
5398-
options->line_prefix_length = strlen(options->line_prefix);
53995398
graph_setup_line_prefix(options);
54005399
return 0;
54015400
}

diff.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ struct diff_options {
274274
const char *single_follow;
275275
const char *a_prefix, *b_prefix;
276276
const char *line_prefix;
277-
size_t line_prefix_length;
278277

279278
/**
280279
* collection of boolean options that affects the operation, but some do

graph.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt)
7474
if (!diffopt || !diffopt->line_prefix)
7575
return;
7676

77-
fwrite(diffopt->line_prefix,
78-
sizeof(char),
79-
diffopt->line_prefix_length,
80-
diffopt->file);
77+
fputs(diffopt->line_prefix, diffopt->file);
8178
}
8279

8380
static const char **column_colors;
@@ -321,8 +318,7 @@ static struct strbuf *diff_output_prefix_callback(struct diff_options *opt, void
321318

322319
strbuf_reset(&msgbuf);
323320
if (opt->line_prefix)
324-
strbuf_add(&msgbuf, opt->line_prefix,
325-
opt->line_prefix_length);
321+
strbuf_addstr(&msgbuf, opt->line_prefix);
326322
if (graph)
327323
graph_padding_line(graph, &msgbuf);
328324
return &msgbuf;

0 commit comments

Comments
 (0)