From: Vsevolod Stakhov Date: Mon, 11 Apr 2016 09:08:32 +0000 (+0100) Subject: [Minor] Slightly simplify swap for optimization X-Git-Tag: 1.2.3~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4042cbffcaf3f9e0d273806b065d18d703d4e78e;p=thirdparty%2Frspamd.git [Minor] Slightly simplify swap for optimization --- diff --git a/src/libutil/heap.c b/src/libutil/heap.c index 115b2e6a83..47c9967325 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))