Skip to content

Commit 2a7a08b

Browse files
committed
Simplified swap operation to not use any temp vars
The power of XOR!
1 parent f33754e commit 2a7a08b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/carbon_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* @param x The first variable.
5757
* @param y The second variable.
5858
*/
59-
#define CARBON_SWAP(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
59+
#define CARBON_SWAP(x, y) { x ^= y; y ^= x; x ^= y; }
6060

6161
#if defined(__has_builtin) && !defined(CARBON_NO_BUILTIN)
6262
#define CARBON_HAS_BUILTIN __has_builtin

0 commit comments

Comments
 (0)