The new function operates on virDomainMomentObjPtr which is indicated by its name. To avoid code duplication, virDomainMomentObjListFindLeaf() was reimplemented in terms of the new function. Signed-off-by: Pavel Mores <pmores@xxxxxxxxxx> --- src/conf/virdomainmomentobjlist.c | 25 +++++++++++++++---------- src/conf/virdomainmomentobjlist.h | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentobjlist.c index 41e887ba18..c57d9cc787 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -207,6 +207,20 @@ virDomainMomentMoveChildren(virDomainMomentObjPtr from, } +/* If there is exactly one leaf node, return that node. */ +virDomainMomentObjPtr +virDomainMomentFindLeaf(virDomainMomentObjPtr moment) +{ + if (moment->nchildren != 1) + return NULL; + while (moment->nchildren == 1) + moment = moment->first_child; + if (moment->nchildren == 0) + return moment; + return NULL; +} + + static virDomainMomentObjPtr virDomainMomentObjNew(void) { @@ -586,17 +600,8 @@ virDomainMomentCheckCycles(virDomainMomentObjListPtr list, return 0; } -/* If there is exactly one leaf node, return that node. */ virDomainMomentObjPtr virDomainMomentObjListFindLeaf(virDomainMomentObjListPtr list) { - virDomainMomentObjPtr moment = &list->metaroot; - - if (moment->nchildren != 1) - return NULL; - while (moment->nchildren == 1) - moment = moment->first_child; - if (moment->nchildren == 0) - return moment; - return NULL; + return virDomainMomentFindLeaf(&list->metaroot); } diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentobjlist.h index cab51edbc4..9c2d01ff8f 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -62,6 +62,7 @@ void virDomainMomentMoveChildren(virDomainMomentObjPtr from, virDomainMomentObjPtr to); void virDomainMomentLinkParent(virDomainMomentObjListPtr moments, virDomainMomentObjPtr moment); +virDomainMomentObjPtr virDomainMomentFindLeaf(virDomainMomentObjPtr moment); virDomainMomentObjListPtr virDomainMomentObjListNew(void); void virDomainMomentObjListFree(virDomainMomentObjListPtr moments); -- 2.24.1