Skip to content

Commit 045d695

Browse files
committed
diff-delta: avoid using the comma operator
The comma operator is a somewhat obscure C feature that is often used by mistake and can even cause unintentional code flow. That is why the `-Wcomma` option of clang was introduced: To identify unintentional uses of the comma operator. Intentional uses include situations where one wants to avoid curly brackets around multiple statements that need to be guarded by a condition. This is the case here, as the repetitive nature of the statements is easier to see for a human reader this way. At least in my opinion. However, opinions on this differ wildly, take 10 people and you have 10 different preferences. On the Git mailing list, it seems that the consensus is to use the long form instead, so let's do just that. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 7239078 commit 045d695

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

diff-delta.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,31 @@ create_delta(const struct delta_index *index,
438438
op = out + outpos++;
439439
i = 0x80;
440440

441-
if (moff & 0x000000ff)
442-
out[outpos++] = moff >> 0, i |= 0x01;
443-
if (moff & 0x0000ff00)
444-
out[outpos++] = moff >> 8, i |= 0x02;
445-
if (moff & 0x00ff0000)
446-
out[outpos++] = moff >> 16, i |= 0x04;
447-
if (moff & 0xff000000)
448-
out[outpos++] = moff >> 24, i |= 0x08;
449-
450-
if (msize & 0x00ff)
451-
out[outpos++] = msize >> 0, i |= 0x10;
452-
if (msize & 0xff00)
453-
out[outpos++] = msize >> 8, i |= 0x20;
441+
if (moff & 0x000000ff) {
442+
out[outpos++] = moff >> 0;
443+
i |= 0x01;
444+
}
445+
if (moff & 0x0000ff00) {
446+
out[outpos++] = moff >> 8;
447+
i |= 0x02;
448+
}
449+
if (moff & 0x00ff0000) {
450+
out[outpos++] = moff >> 16;
451+
i |= 0x04;
452+
}
453+
if (moff & 0xff000000) {
454+
out[outpos++] = moff >> 24;
455+
i |= 0x08;
456+
}
457+
458+
if (msize & 0x00ff) {
459+
out[outpos++] = msize >> 0;
460+
i |= 0x10;
461+
}
462+
if (msize & 0xff00) {
463+
out[outpos++] = msize >> 8;
464+
i |= 0x20;
465+
}
454466

455467
*op = i;
456468

0 commit comments

Comments
 (0)