From e3c4ad4b17e9d303c3f5c0b847f5e1cc96134398 Mon Sep 17 00:00:00 2001 From: Barak Itkin Date: Sat, 28 Jul 2012 22:25:06 +0300 Subject: [PATCH] Fix a fatal error which caused evaluation of set element expressions twice! This caused not only a performance penalty, but also a memory leak since in some places the expression was p2tr_edge_ref (...) --- poly2tri-c/refine/utils.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/poly2tri-c/refine/utils.h b/poly2tri-c/refine/utils.h index ca4dbba..576476f 100644 --- a/poly2tri-c/refine/utils.h +++ b/poly2tri-c/refine/utils.h @@ -49,7 +49,17 @@ extern "C" #define p2tr_hash_set_new_default() g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL) #define p2tr_hash_set_new(hash_func, equal_func, destroy) g_hash_table_new_full ((hash_func), (equal_func), (destroy),NULL) -#define p2tr_hash_set_insert(set,element) g_hash_table_insert ((set), (element), (element)) +#define p2tr_hash_set_insert(set,element) \ +G_STMT_START \ +{ \ + /* The "obvious" code (presented below) won't work: */ \ + /* g_hash_table_insert ((set), (element), (element)) */ \ + /* since it will cause double evaluation of (element) which is a */ \ + /* problem! */ \ + gpointer P2TR_HASH_SET_ELEM = (element); \ + g_hash_table_insert ((set), P2TR_HASH_SET_ELEM, P2TR_HASH_SET_ELEM); \ +} \ +G_STMT_END #define p2tr_hash_set_contains(set,element) g_hash_table_lookup_extended ((set), (element), NULL, NULL) #define p2tr_hash_set_remove(set,element) g_hash_table_remove ((set), (element)) #define p2tr_hash_set_remove_all(set) g_hash_table_remove_all ((set)) -- 2.50.1