From 16d0588d981854519771046e7a3db5f731d5712c Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 28 Jun 2015 14:20:12 +0200 Subject: [PATCH] isl_union_*_dup: extract out isl_union_*_transform The same pattern occurs in several functions in isl_union_templ.c The other functions will be converted in subsequent commits. Signed-off-by: Sven Verdoolaege --- isl_union_templ.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/isl_union_templ.c b/isl_union_templ.c index 389050c7..d8eb0e4b 100644 --- a/isl_union_templ.c +++ b/isl_union_templ.c @@ -421,29 +421,27 @@ static __isl_give UNION *FN(UNION,transform_space)(__isl_take UNION *u, return data.res; } -static isl_stat FN(UNION,add_part)(__isl_take PART *part, void *user) +/* Return a UNION that lives in the same space as "u" and that is obtained + * by applying "fn" to each of the entries in "u". + */ +static __isl_give UNION *FN(UNION,transform)(__isl_take UNION *u, + __isl_give PART *(*fn)(__isl_take PART *part, void *user), void *user) { - UNION **u = (UNION **)user; - - *u = FN(FN(UNION,add),PARTS)(*u, part); + return FN(UNION,transform_space)(u, FN(UNION,get_space)(u), fn, user); +} - return isl_stat_ok; +/* An isl_union_*_transform callback for use in isl_union_*_dup + * that simply returns "part". + */ +static __isl_give PART *FN(UNION,copy_part)(__isl_take PART *part, void *user) +{ + return part; } __isl_give UNION *FN(UNION,dup)(__isl_keep UNION *u) { - UNION *dup; - - if (!u) - return NULL; - - dup = FN(UNION,alloc_same_size)(u); - if (FN(FN(UNION,foreach),PARTS)(u, &FN(UNION,add_part), &dup) < 0) - goto error; - return dup; -error: - FN(UNION,free)(dup); - return NULL; + u = FN(UNION,copy)(u); + return FN(UNION,transform)(u, &FN(UNION,copy_part), NULL); } __isl_give UNION *FN(UNION,cow)(__isl_take UNION *u) -- 2.11.4.GIT