Fabric: Composing YGNode object inside ShadowNode to avoid memory allocation overhead

Summary:
Given that fact that life-time of YGNode and ShadowNode objects must be idential and that we always allocate ShadowNode on heap,
we can embed YGNode object right inside ShadowNode object and use pointer to it safely.
That allows us to save additional memory allocation for every single layoutable shadow node! Whoo-hoo!

Reviewed By: fkgozali

Differential Revision: D8070121

fbshipit-source-id: 6eefbca1b7ac0a8aad235513b4c4899d414835f2
This commit is contained in:
Valentin Shergin
2018-05-22 15:45:55 -07:00
committed by Facebook Github Bot
parent b8f30db0ae
commit d94a9e2640
3 changed files with 35 additions and 30 deletions

View File

@@ -22,8 +22,7 @@ void RootShadowNode::layout() {
// This is the rare place where shadow node must layout (set `layoutMetrics`)
// itself because there is no a parent node which usually should do it.
YGNode *yogaNode = const_cast<YGNode *>(yogaNode_.get());
setLayoutMetrics(layoutMetricsFromYogaNode(*yogaNode));
setLayoutMetrics(layoutMetricsFromYogaNode(yogaNode_));
}
} // namespace react