Re: Improved Swapping Method In sort.c

From: David Newall
Date: Wed Apr 30 2008 - 14:47:03 EST


Soumyadip Das Mahapatra wrote:
> static void u32_swap(void *a, void *b)
> {
> *(u32 *)b ^= *(u32 *)a ^= *(u32 *)b ^= *(u32 *)a;
> }
>

That was posted to comp.lang.c 20 years ago or more. It's not something
that the compiler is likely to be able to optimize (unlike the normal
swap, using a temporary variable.)

Another cute, temp-free swap, from the same era, is: b += a -= b; a = b - a.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/