diff options
author | Stefan Beller <sbeller@google.com> | 2018-08-14 04:41:20 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-08-15 00:03:05 +0300 |
commit | 29ef759d7ca039590240890a604be8308b30a069 (patch) | |
tree | 0451b2733583f158fd37251ed1e514752055d55d /diff.c | |
parent | 017ac45e87074a51e7bf926b8f87152a1af9a441 (diff) |
diff: use emit_line_0 once per line
All lines that use emit_line_0 multiple times per line, are combined
into a single call to emit_line_0, making use of the 'set' argument.
We gain a little efficiency here, as we can omit emission of color and
accompanying reset if 'len == 0'.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -656,12 +656,14 @@ static void emit_line_0(struct diff_options *o, fputs(set_sign, file); if (first && !nofirst) fputc(first, file); - if (set && set != set_sign) { - if (set_sign) - fputs(reset, file); - fputs(set, file); + if (len) { + if (set && set != set_sign) { + if (set_sign) + fputs(reset, file); + fputs(set, file); + } + fwrite(line, len, 1, file); } - fwrite(line, len, 1, file); fputs(reset, file); } if (has_trailing_carriage_return) @@ -1207,9 +1209,7 @@ static void emit_line_ws_markup(struct diff_options *o, if (!ws && !set_sign) emit_line_0(o, set, NULL, 0, reset, sign, line, len); else if (!ws) { - /* Emit just the prefix, then the rest. */ - emit_line_0(o, set_sign, NULL, !!set_sign, reset, sign, "", 0); - emit_line_0(o, set, NULL, 0, reset, 0, line, len); + emit_line_0(o, set_sign, set, !!set_sign, reset, sign, line, len); } else if (blank_at_eof) /* Blank line at EOF - paint '+' as well */ emit_line_0(o, ws, NULL, 0, reset, sign, line, len); |