Skip to content

Commit b5571cd

Browse files
Tomas Reimersfacebook-github-bot
Tomas Reimers
authored andcommitted
Create a recursive free with cleanup function
Reviewed By: davidaurelio Differential Revision: D13119307 fbshipit-source-id: 162bb4fd6d7620f61cbac010d0dc236d81738b71
1 parent e61a14e commit b5571cd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: ReactCommon/yoga/yoga/Yoga.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ static void YGConfigFreeRecursive(const YGNodeRef root) {
319319
}
320320
}
321321

322-
void YGNodeFreeRecursive(const YGNodeRef root) {
322+
void YGNodeFreeRecursiveWithCleanupFunc(
323+
const YGNodeRef root,
324+
YGNodeCleanupFunc cleanup) {
323325
while (YGNodeGetChildCount(root) > 0) {
324326
const YGNodeRef child = YGNodeGetChild(root, 0);
325327
if (child->getOwner() != root) {
@@ -329,9 +331,16 @@ void YGNodeFreeRecursive(const YGNodeRef root) {
329331
YGNodeRemoveChild(root, child);
330332
YGNodeFreeRecursive(child);
331333
}
334+
if (cleanup != nullptr) {
335+
cleanup(root);
336+
}
332337
YGNodeFree(root);
333338
}
334339

340+
void YGNodeFreeRecursive(const YGNodeRef root) {
341+
return YGNodeFreeRecursiveWithCleanupFunc(root, nullptr);
342+
}
343+
335344
void YGNodeReset(const YGNodeRef node) {
336345
YGAssertWithNode(
337346
node,

Diff for: ReactCommon/yoga/yoga/Yoga.h

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ typedef float (
7070
*YGBaselineFunc)(YGNodeRef node, const float width, const float height);
7171
typedef void (*YGDirtiedFunc)(YGNodeRef node);
7272
typedef void (*YGPrintFunc)(YGNodeRef node);
73+
typedef void (*YGNodeCleanupFunc)(YGNodeRef node);
7374
typedef int (*YGLogger)(
7475
const YGConfigRef config,
7576
const YGNodeRef node,
@@ -84,6 +85,9 @@ WIN_EXPORT YGNodeRef YGNodeNew(void);
8485
WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config);
8586
WIN_EXPORT YGNodeRef YGNodeClone(const YGNodeRef node);
8687
WIN_EXPORT void YGNodeFree(const YGNodeRef node);
88+
WIN_EXPORT void YGNodeFreeRecursiveWithCleanupFunc(
89+
const YGNodeRef node,
90+
YGNodeCleanupFunc cleanup);
8791
WIN_EXPORT void YGNodeFreeRecursive(const YGNodeRef node);
8892
WIN_EXPORT void YGNodeReset(const YGNodeRef node);
8993
WIN_EXPORT int32_t YGNodeGetInstanceCount(void);

0 commit comments

Comments
 (0)