Replace XOR swapping by default ("naive", with extra var) one.
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 21 Jan 2014 14:19:27 +0000 (15:19 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 21 Jan 2014 14:50:44 +0000 (15:50 +0100)
Ref: http://en.wikipedia.org/wiki/XOR_swap_algorithm, modern compilers/CPUs are much more efficient with "naive" algo than XOR one.
Doubled check, for me in an optimized build, XOR is several times slower than naive algo.

source/blender/blenlib/intern/edgehash.c
source/blender/bmesh/tools/bmesh_beautify.c

index 50dcd01207d4b70948d5e960ae9f375a63e12762..1d0c9b20550bdca4d63bdc91f097ebf22eeaf4ff 100644 (file)
@@ -59,11 +59,9 @@ static const unsigned int _ehash_hashsizes[] = {
 #endif
 
 /* ensure v0 is smaller */
-#define EDGE_ORD(v0, v1) \
-       if (v0 > v1) {       \
-               v0 ^= v1;        \
-               v1 ^= v0;        \
-               v0 ^= v1;        \
+#define EDGE_ORD(v0, v1)            \
+       if (v0 > v1) {                  \
+               SWAP(unsigned int, v0, v1); \
        } (void)0
 
 /***/
index 45093f952d8f46c684c0b4b355a051a2eb653d27..4b5c87892278e58c1fa6777fc62c933b6cf6d4f1 100644 (file)
@@ -90,11 +90,9 @@ static GSet *erot_gset_new(void)
 }
 
 /* ensure v0 is smaller */
-#define EDGE_ORD(v0, v1) \
-       if (v0 > v1) {       \
-               v0 ^= v1;        \
-               v1 ^= v0;        \
-               v0 ^= v1;        \
+#define EDGE_ORD(v0, v1)   \
+       if (v0 > v1) {         \
+               SWAP(int, v0, v1); \
        } (void)0
 
 static void erot_state_ex(const BMEdge *e, int v_index[2], int f_index[2])