The function usually gets inlined anyway (depending on your compiler) and if it starts with if x == y { return } then it just compiles to if x != y { /* swap x and y */ }
In fact, might as well use a temporary variable at that point if you're expecting for compiler optimizations :shrug:. At that point they'd just become temporary registers and wouldn't have anything in memory, and a single xchg call
Which would be inefficient, thus not recommended.
The function usually gets inlined anyway (depending on your compiler) and if it starts with
if x == y { return }
then it just compiles toif x != y { /* swap x and y */ }
In fact, might as well use a temporary variable at that point if you're expecting for compiler optimizations :shrug:. At that point they'd just become temporary registers and wouldn't have anything in memory, and a single
xchg
callYou could just write the registers yourself then...