diff --git a/tests/YGTreeMutationTest.cpp b/tests/YGTreeMutationTest.cpp index 3b9e6a39ef..5c0cc51859 100644 --- a/tests/YGTreeMutationTest.cpp +++ b/tests/YGTreeMutationTest.cpp @@ -23,11 +23,11 @@ TEST(YogaTest, set_children_adds_children_to_parent) { YGNodeRef const root_child0 = YGNodeNew(); YGNodeRef const root_child1 = YGNodeNew(); - YGNodeSetChildren(root, {root_child0, root_child1}); + YGNodeRef children[] = {root_child0, root_child1}; + YGNodeSetChildren(root, children, 2); - const std::vector children = getChildren(root); const std::vector expectedChildren = {root_child0, root_child1}; - ASSERT_EQ(children, expectedChildren); + ASSERT_EQ(getChildren(root), expectedChildren); const std::vector owners = { YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; @@ -42,12 +42,12 @@ TEST(YogaTest, set_children_to_empty_removes_old_children) { YGNodeRef const root_child0 = YGNodeNew(); YGNodeRef const root_child1 = YGNodeNew(); - YGNodeSetChildren(root, {root_child0, root_child1}); - YGNodeSetChildren(root, {}); + YGNodeRef children[] = {root_child0, root_child1}; + YGNodeSetChildren(root, children, 2); + YGNodeSetChildren(root, nullptr, 0); - const std::vector children = getChildren(root); const std::vector expectedChildren = {}; - ASSERT_EQ(children, expectedChildren); + ASSERT_EQ(getChildren(root), expectedChildren); const std::vector owners = { YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; @@ -62,16 +62,17 @@ TEST(YogaTest, set_children_replaces_non_common_children) { YGNodeRef const root_child0 = YGNodeNew(); YGNodeRef const root_child1 = YGNodeNew(); - YGNodeSetChildren(root, {root_child0, root_child1}); + YGNodeRef children1[] = {root_child0, root_child1}; + YGNodeSetChildren(root, children1, 2); YGNodeRef const root_child2 = YGNodeNew(); YGNodeRef const root_child3 = YGNodeNew(); - YGNodeSetChildren(root, {root_child2, root_child3}); + YGNodeRef children2[] = {root_child2, root_child3}; + YGNodeSetChildren(root, children2, 2); - const std::vector children = getChildren(root); const std::vector expectedChildren = {root_child2, root_child3}; - ASSERT_EQ(children, expectedChildren); + ASSERT_EQ(getChildren(root), expectedChildren); const std::vector owners = { YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; @@ -89,16 +90,17 @@ TEST(YogaTest, set_children_keeps_and_reorders_common_children) { YGNodeRef const root_child1 = YGNodeNew(); YGNodeRef const root_child2 = YGNodeNew(); - YGNodeSetChildren(root, {root_child0, root_child1, root_child2}); + YGNodeRef children1[] = {root_child0, root_child1, root_child2}; + YGNodeSetChildren(root, children1, 3); YGNodeRef const root_child3 = YGNodeNew(); - YGNodeSetChildren(root, {root_child2, root_child1, root_child3}); + YGNodeRef children2[] = {root_child2, root_child1, root_child3}; + YGNodeSetChildren(root, children2, 3); - const std::vector children = getChildren(root); const std::vector expectedChildren = { root_child2, root_child1, root_child3}; - ASSERT_EQ(children, expectedChildren); + ASSERT_EQ(getChildren(root), expectedChildren); const std::vector owners = { YGNodeGetOwner(root_child0), diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 78486e2e95..ddacd6036c 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -379,13 +379,16 @@ YOGA_EXPORT void YGNodeRemoveAllChildren(const YGNodeRef owner) { owner->markDirtyAndPropagate(); } -static void YGNodeSetChildrenInternal( - YGNodeRef const owner, - const std::vector& children) { +YOGA_EXPORT void YGNodeSetChildren( + const YGNodeRef owner, + const YGNodeRef* children, + const uint32_t count) { if (!owner) { return; } - if (children.size() == 0) { + + const YGVector childrenVector = {children, children + count}; + if (childrenVector.size() == 0) { if (YGNodeGetChildCount(owner) > 0) { for (YGNodeRef const child : owner->getChildren()) { child->setLayout(YGLayout()); @@ -399,35 +402,21 @@ static void YGNodeSetChildrenInternal( for (YGNodeRef const oldChild : owner->getChildren()) { // Our new children may have nodes in common with the old children. We // don't reset these common nodes. - if (std::find(children.begin(), children.end(), oldChild) == - children.end()) { + if (std::find(childrenVector.begin(), childrenVector.end(), oldChild) == + childrenVector.end()) { oldChild->setLayout(YGLayout()); oldChild->setOwner(nullptr); } } } - owner->setChildren(children); - for (YGNodeRef child : children) { + owner->setChildren(childrenVector); + for (YGNodeRef child : childrenVector) { child->setOwner(owner); } owner->markDirtyAndPropagate(); } } -YOGA_EXPORT void YGNodeSetChildren( - const YGNodeRef owner, - const YGNodeRef c[], - const uint32_t count) { - const YGVector children = {c, c + count}; - YGNodeSetChildrenInternal(owner, children); -} - -YOGA_EXPORT void YGNodeSetChildren( - YGNodeRef const owner, - const std::vector& children) { - YGNodeSetChildrenInternal(owner, children); -} - YOGA_EXPORT YGNodeRef YGNodeGetChild(const YGNodeRef node, const uint32_t index) { if (index < node->getChildren().size()) { diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 7b57968700..3eee36928f 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -82,7 +82,7 @@ WIN_EXPORT YGNodeRef YGNodeGetParent(YGNodeRef node); WIN_EXPORT uint32_t YGNodeGetChildCount(YGNodeRef node); WIN_EXPORT void YGNodeSetChildren( YGNodeRef owner, - const YGNodeRef children[], + const YGNodeRef* children, uint32_t count); WIN_EXPORT void YGNodeSetIsReferenceBaseline( @@ -364,11 +364,3 @@ WIN_EXPORT float YGRoundValueToPixelGrid( bool forceFloor); YG_EXTERN_C_END - -#ifdef __cplusplus - -#include - -void YGNodeSetChildren(YGNodeRef owner, const std::vector& children); - -#endif