Create a recursive free with cleanup function

Reviewed By: davidaurelio

Differential Revision: D13119307

fbshipit-source-id: 162bb4fd6d7620f61cbac010d0dc236d81738b71
This commit is contained in:
Tomas Reimers
2018-11-26 16:00:37 -08:00
committed by Facebook Github Bot
parent 8e48edaa0b
commit 9725d5b21b
2 changed files with 14 additions and 1 deletions

View File

@@ -319,7 +319,9 @@ static void YGConfigFreeRecursive(const YGNodeRef root) {
}
}
void YGNodeFreeRecursive(const YGNodeRef root) {
void YGNodeFreeRecursiveWithCleanupFunc(
const YGNodeRef root,
YGNodeCleanupFunc cleanup) {
while (YGNodeGetChildCount(root) > 0) {
const YGNodeRef child = YGNodeGetChild(root, 0);
if (child->getOwner() != root) {
@@ -329,9 +331,16 @@ void YGNodeFreeRecursive(const YGNodeRef root) {
YGNodeRemoveChild(root, child);
YGNodeFreeRecursive(child);
}
if (cleanup != nullptr) {
cleanup(root);
}
YGNodeFree(root);
}
void YGNodeFreeRecursive(const YGNodeRef root) {
return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr);
}
void YGNodeReset(const YGNodeRef node) {
YGAssertWithNode(
node,