[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4818BE97.7030307@davidnewall.com>
Date: Thu, 01 May 2008 04:16:47 +0930
From: David Newall <davidn@...idnewall.com>
To: Soumyadip Das Mahapatra <dip_kernel@...oo.co.in>
CC: linux-kernel@...r.kernel.org
Subject: Re: Improved Swapping Method In sort.c
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists