From f12211ab514eaa81f4e39428eb4c8d868f07d328 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 28 Jun 2015 20:51:45 +0200 Subject: [PATCH] isl_union_templ.c: extract out shared isl_union_*_remove_part_entry Signed-off-by: Sven Verdoolaege --- isl_fold.c | 7 +++---- isl_union_templ.c | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/isl_fold.c b/isl_fold.c index a89c507a..d61d41fd 100644 --- a/isl_fold.c +++ b/isl_fold.c @@ -1413,10 +1413,9 @@ static isl_stat add_pwqp(__isl_take isl_pw_qpolynomial *pwqp, void *user) entry->data = isl_pw_qpolynomial_fold_add(entry->data, pwf); if (!entry->data) return isl_stat_error; - if (isl_pw_qpolynomial_fold_is_zero(entry->data)) { - isl_pw_qpolynomial_fold_free(entry->data); - isl_hash_table_remove(ctx, &(*upwf)->table, entry); - } + if (isl_pw_qpolynomial_fold_is_zero(entry->data)) + *upwf = isl_union_pw_qpolynomial_fold_remove_part_entry( + *upwf, entry); } return isl_stat_ok; diff --git a/isl_union_templ.c b/isl_union_templ.c index 6f44b7c1..f24de090 100644 --- a/isl_union_templ.c +++ b/isl_union_templ.c @@ -210,6 +210,23 @@ static struct isl_hash_table_entry *FN(UNION,find_part_entry)( "expression over a given domain", return NULL); } +/* Remove "part_entry" from the hash table of "u". + */ +static __isl_give UNION *FN(UNION,remove_part_entry)(__isl_take UNION *u, + struct isl_hash_table_entry *part_entry) +{ + isl_ctx *ctx; + + if (!u || !part_entry) + return FN(UNION,free)(u); + + ctx = FN(UNION,get_ctx)(u); + isl_hash_table_remove(ctx, &u->table, part_entry); + FN(PART,free)(part_entry->data); + + return u; +} + /* Extract the element of "u" living in "space" (ignoring parameters). * * Return the ZERO element if "u" does not contain any element @@ -296,10 +313,8 @@ static __isl_give UNION *FN(UNION,add_part_generic)(__isl_take UNION *u, empty = FN(PART,IS_ZERO)(part); if (empty < 0) goto error; - if (empty) { - FN(PART,free)(entry->data); - isl_hash_table_remove(u->space->ctx, &u->table, entry); - } + if (empty) + u = FN(UNION,remove_part_entry)(u, entry); FN(PART,free)(part); } -- 2.11.4.GIT