mirror of
https://github.com/git/git.git
synced 2024-10-30 05:47:53 +01:00
568edcb95a
Add a macro for exchanging the values of variables. It allows users to avoid repetition and takes care of the temporary variable for them. It also makes sure that the storage sizes of its two parameters are the same. Its memcpy(1) calls are optimized away by current compilers. Also add a conservative semantic patch for transforming only swaps of variables of the same type. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
28 lines
280 B
Text
28 lines
280 B
Text
@ swap_with_declaration @
|
|
type T;
|
|
identifier tmp;
|
|
T a, b;
|
|
@@
|
|
- T tmp = a;
|
|
+ T tmp;
|
|
+ tmp = a;
|
|
a = b;
|
|
b = tmp;
|
|
|
|
@ swap @
|
|
type T;
|
|
T tmp, a, b;
|
|
@@
|
|
- tmp = a;
|
|
- a = b;
|
|
- b = tmp;
|
|
+ SWAP(a, b);
|
|
|
|
@ extends swap @
|
|
identifier unused;
|
|
@@
|
|
{
|
|
...
|
|
- T unused;
|
|
... when != unused
|
|
}
|