From 4042cbffcaf3f9e0d273806b065d18d703d4e78e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 11 Apr 2016 10:08:32 +0100 Subject: [PATCH] [Minor] Slightly simplify swap for optimization --- src/libutil/heap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/libutil/heap.c b/src/libutil/heap.c index 115b2e6a8..47c996732 100644 --- a/src/libutil/heap.c +++ b/src/libutil/heap.c @@ -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)) -- 2.39.5