mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fabric: Being even smarter preserving dirty flag on Yoga nodes
Summary: In addition to the previous change, now we handle a situation where some node receives a new set of children and all those children have the same styles. (See the previous diff for more details.) Reviewed By: JoshuaGross Differential Revision: D14472754 fbshipit-source-id: 16411036e14f18e730e064e33948440b05ff51c8
This commit is contained in:
committed by
Facebook Github Bot
parent
d6d381180b
commit
6bd67de4d3
@@ -95,12 +95,25 @@ void YogaLayoutableShadowNode::appendChild(YogaLayoutableShadowNode *child) {
|
||||
void YogaLayoutableShadowNode::setChildren(
|
||||
YogaLayoutableShadowNode::UnsharedList children) {
|
||||
ensureUnsealed();
|
||||
yogaNode_.setDirty(true);
|
||||
|
||||
// Optimization:
|
||||
// If the new list of child nodes consists of clean nodes, and if their styles
|
||||
// are identical to styles of old children, we don't dirty the node.
|
||||
bool isClean = !yogaNode_.getDirtied() &&
|
||||
children.size() == yogaNode_.getChildren().size();
|
||||
auto oldChildren = isClean ? yogaNode_.getChildren() : YGVector{};
|
||||
|
||||
yogaNode_.setChildren({});
|
||||
for (const auto &child : children) {
|
||||
|
||||
auto i = int{0};
|
||||
for (auto const &child : children) {
|
||||
appendChild(child);
|
||||
|
||||
isClean = isClean && !child->yogaNode_.isDirty() &&
|
||||
child->yogaNode_.getStyle() == oldChildren[i++]->getStyle();
|
||||
}
|
||||
|
||||
yogaNode_.setDirty(!isClean);
|
||||
}
|
||||
|
||||
void YogaLayoutableShadowNode::setProps(const YogaStylableProps &props) {
|
||||
|
||||
Reference in New Issue
Block a user