Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/diff/diffreg.c
Show First 20 Lines • Show All 1,241 Lines • ▼ Show 20 Lines | if (diff_format != D_IFDEF && diff_format != D_GFORMAT && | ||||
if (Tflag && (diff_format == D_NORMAL || | if (Tflag && (diff_format == D_NORMAL || | ||||
diff_format == D_CONTEXT || | diff_format == D_CONTEXT || | ||||
diff_format == D_UNIFIED)) | diff_format == D_UNIFIED)) | ||||
printf("\t"); | printf("\t"); | ||||
else if (diff_format != D_UNIFIED) | else if (diff_format != D_UNIFIED) | ||||
printf(" "); | printf(" "); | ||||
} | } | ||||
col = 0; | col = 0; | ||||
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { | for (j = 0, lastc = '\0'; j < nc && (hw == 0 || col < hw); | ||||
j++, lastc = c) { | |||||
pstef: style suggestion: we could move the initialization to before this loop, move the step part to… | |||||
Done Inline ActionsThat feels like possible bikeshed bait, so I've queued it up as a second commit in case someone complains about it. kevans: That feels like possible bikeshed bait, so I've queued it up as a second commit in case someone… | |||||
c = getc(lb); | c = getc(lb); | ||||
if (flags & D_STRIPCR && c == '\r') { | if (flags & D_STRIPCR && c == '\r') { | ||||
if ((c = getc(lb)) == '\n') | if ((c = getc(lb)) == '\n') | ||||
j++; | j++; | ||||
else { | else { | ||||
ungetc(c, lb); | ungetc(c, lb); | ||||
c = '\r'; | c = '\r'; | ||||
} | } | ||||
Show All 10 Lines | for (j = 0, lastc = '\0'; j < nc && (hw == 0 || col < hw); | ||||
/* | /* | ||||
* when using --side-by-side, col needs to be increased | * when using --side-by-side, col needs to be increased | ||||
* in any case to keep the columns aligned | * in any case to keep the columns aligned | ||||
*/ | */ | ||||
if (c == '\t') { | if (c == '\t') { | ||||
if (flags & D_EXPANDTABS) { | if (flags & D_EXPANDTABS) { | ||||
newcol = ((col / tabsize) + 1) * tabsize; | newcol = ((col / tabsize) + 1) * tabsize; | ||||
do { | do { | ||||
if (diff_format == D_SIDEBYSIDE) | |||||
j++; | |||||
printf(" "); | printf(" "); | ||||
} while (++col < newcol && j < nc); | } while (++col < newcol && col < hw); | ||||
Not Done Inline ActionsI don't feel strongly about printf performance in diff, but calling printf within a loop doesn't look great. Of course I understand this code isn't new so may be out of the scope of this patch. Just can't not see it. pstef: I don't feel strongly about printf performance in diff, but calling printf within a loop… | |||||
Done Inline ActionsYeah, I'm going to punt on this one -- most of the time we're talking <= 8 iterations at a time, and this is a non-default path. kevans: Yeah, I'm going to punt on this one -- most of the time we're talking <= 8 iterations at a time… | |||||
} else { | } else { | ||||
if (diff_format == D_SIDEBYSIDE) { | if (diff_format == D_SIDEBYSIDE) { | ||||
if ((j + tabsize) > nc) { | if ((col + tabsize) > hw) { | ||||
printf("%*s", nc - j, ""); | printf("%*s", hw - col, ""); | ||||
j = col = nc; | col = hw; | ||||
} else { | } else { | ||||
printf("\t"); | printf("\t"); | ||||
col += tabsize - 1; | col += tabsize - 1; | ||||
j += tabsize - 1; | |||||
} | } | ||||
} else { | } else { | ||||
printf("\t"); | printf("\t"); | ||||
col++; | col++; | ||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
if (diff_format == D_EDIT && j == 1 && c == '\n' && | if (diff_format == D_EDIT && j == 1 && c == '\n' && | ||||
▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines |
style suggestion: we could move the initialization to before this loop, move the step part to the end of the loop (there are no continues or breaks) and keep the condition within a while ()