Skip to content

Commit 402bf8e

Browse files
rscharfegitster
authored andcommitted
diff: use SWAP macro
Use the macro SWAP to exchange the value of pairs of variables instead of swapping them manually with the help of a temporary variable. The resulting code is shorter and easier to read. The two cases were not transformed by the semantic patch swap.cocci because it's extra careful and handles only cases where the types of all variables are the same -- and here we swap two ints and use an unsigned temporary variable for that. Nevertheless the conversion is safe, as the value range is preserved with and without the patch. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 35d803b commit 402bf8e

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

diff-no-index.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ static int queue_diff(struct diff_options *o,
185185
struct diff_filespec *d1, *d2;
186186

187187
if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
188-
unsigned tmp;
189-
tmp = mode1; mode1 = mode2; mode2 = tmp;
188+
SWAP(mode1, mode2);
190189
SWAP(name1, name2);
191190
}
192191

diff.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,11 +5117,9 @@ void diff_change(struct diff_options *options,
51175117
return;
51185118

51195119
if (DIFF_OPT_TST(options, REVERSE_DIFF)) {
5120-
unsigned tmp;
51215120
SWAP(old_mode, new_mode);
51225121
SWAP(old_sha1, new_sha1);
5123-
tmp = old_sha1_valid; old_sha1_valid = new_sha1_valid;
5124-
new_sha1_valid = tmp;
5122+
SWAP(old_sha1_valid, new_sha1_valid);
51255123
SWAP(old_dirty_submodule, new_dirty_submodule);
51265124
}
51275125

0 commit comments

Comments
 (0)