@@ -348,36 +348,6 @@ static void YGNodeMarkDirtyInternal(const YGNodeRef node) {
348
348
}
349
349
}
350
350
351
- static void YGCloneChildrenIfNeeded (const YGNodeRef parent) {
352
- // YGNodeRemoveChild has a forked variant of this algorithm optimized for deletions.
353
- const uint32_t childCount = YGNodeGetChildCount (parent);
354
- if (childCount == 0 ) {
355
- // This is an empty set. Nothing to clone.
356
- return ;
357
- }
358
-
359
- const YGNodeRef firstChild = YGNodeGetChild (parent, 0 );
360
- if (firstChild->getParent () == parent) {
361
- // If the first child has this node as its parent, we assume that it is already unique.
362
- // We can do this because if we have it has a child, that means that its parent was at some
363
- // point cloned which made that subtree immutable.
364
- // We also assume that all its sibling are cloned as well.
365
- return ;
366
- }
367
-
368
- const YGNodeClonedFunc cloneNodeCallback =
369
- parent->getConfig ()->cloneNodeCallback ;
370
- for (uint32_t i = 0 ; i < childCount; i++) {
371
- const YGNodeRef oldChild = parent->getChild (i);
372
- const YGNodeRef newChild = YGNodeClone (oldChild);
373
- parent->replaceChild (newChild, i);
374
- newChild->setParent (parent);
375
- if (cloneNodeCallback) {
376
- cloneNodeCallback (oldChild, newChild, parent, i);
377
- }
378
- }
379
- }
380
-
381
351
void YGNodeInsertChild (const YGNodeRef node, const YGNodeRef child, const uint32_t index) {
382
352
YGAssertWithNode (
383
353
node,
@@ -388,14 +358,15 @@ void YGNodeInsertChild(const YGNodeRef node, const YGNodeRef child, const uint32
388
358
node->getMeasure () == nullptr ,
389
359
" Cannot add child: Nodes with measure functions cannot have children." );
390
360
391
- YGCloneChildrenIfNeeded ( node);
361
+ node-> cloneChildrenIfNeeded ( );
392
362
node->insertChild (child, index );
393
363
child->setParent (node);
394
364
YGNodeMarkDirtyInternal (node);
395
365
}
396
366
397
367
void YGNodeRemoveChild (const YGNodeRef parent, const YGNodeRef excludedChild) {
398
- // This algorithm is a forked variant from YGCloneChildrenIfNeeded that excludes a child.
368
+ // This algorithm is a forked variant from cloneChildrenIfNeeded in YGNode
369
+ // that excludes a child.
399
370
const uint32_t childCount = YGNodeGetChildCount (parent);
400
371
401
372
if (childCount == 0 ) {
@@ -1805,7 +1776,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions(const YGNodeRef node,
1805
1776
static void YGZeroOutLayoutRecursivly (const YGNodeRef node) {
1806
1777
memset (&(node->getLayout ()), 0 , sizeof (YGLayout));
1807
1778
node->setHasNewLayout (true );
1808
- YGCloneChildrenIfNeeded ( node);
1779
+ node-> cloneChildrenIfNeeded ( );
1809
1780
const uint32_t childCount = YGNodeGetChildCount (node);
1810
1781
for (uint32_t i = 0 ; i < childCount; i++) {
1811
1782
const YGNodeRef child = node->getChild (i);
@@ -1993,8 +1964,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
1993
1964
}
1994
1965
1995
1966
// At this point we know we're going to perform work. Ensure that each child has a mutable copy.
1996
- YGCloneChildrenIfNeeded (node);
1997
-
1967
+ node->cloneChildrenIfNeeded ();
1998
1968
// Reset layout flags, as they could have changed.
1999
1969
node->setLayoutHadOverflow (false );
2000
1970
0 commit comments