]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Slightly simplify swap for optimization
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Apr 2016 09:08:32 +0000 (10:08 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 11 Apr 2016 09:08:32 +0000 (10:08 +0100)
src/libutil/heap.c

index 115b2e6a83f1a4bdf34719ea2144c8e227ef8c4f..47c9967325aecac5f39e1e18f7bafa27696bd265 100644 (file)
@@ -21,13 +21,15 @@ struct rspamd_min_heap {
        GPtrArray *ar;
 };
 
+#define __SWAP(a, b) do { \
+       __typeof__(a) _a = (a); \
+       __typeof__(b) _b = (b); \
+       a = _b; \
+       b = _a; \
+} while (0)
 #define heap_swap(h,e1,e2) do { \
-       gpointer telt = (h)->ar->pdata[(e1)->idx - 1]; \
-       (h)->ar->pdata[(e1)->idx - 1] = (h)->ar->pdata[(e2)->idx - 1]; \
-       (h)->ar->pdata[(e2)->idx - 1] = telt; \
-       guint tidx = (e1)->idx; \
-       (e1)->idx = (e2)->idx; \
-       (e2)->idx = tidx; \
+       __SWAP((h)->ar->pdata[(e1)->idx - 1], (h)->ar->pdata[(e2)->idx - 1]); \
+       __SWAP((e1)->idx, (e2)->idx); \
 } while (0)
 
 #define min_elt(e1, e2) ((e1)->pri <= (e2)->pri ? (e1) : (e2))