Fabric: `ParagraphShadowNode::updateLocalDataIfNeeded()`

Summary: Now we don't update `LocalData` for `ParagraphShadowNode` if the attributed string hasn't changed.

Reviewed By: mdvacca

Differential Revision: D13160128

fbshipit-source-id: 6ffe76ad187452fa37ba36a132b885cbcedfd1d3
This commit is contained in:
Valentin Shergin 2018-11-21 17:10:31 -08:00 committed by Facebook Github Bot
parent 7e57755cea
commit 9c961331dd
2 changed files with 10 additions and 4 deletions

View File

@ -32,11 +32,17 @@ void ParagraphShadowNode::setTextLayoutManager(
textLayoutManager_ = textLayoutManager;
}
void ParagraphShadowNode::updateLocalData() {
void ParagraphShadowNode::updateLocalDataIfNeeded() {
ensureUnsealed();
auto attributedString = getAttributedString();
auto currentLocalData = std::static_pointer_cast<const ParagraphLocalData>(getLocalData());
if (currentLocalData && currentLocalData->getAttributedString() == attributedString) {
return;
}
auto localData = std::make_shared<ParagraphLocalData>();
localData->setAttributedString(getAttributedString());
localData->setAttributedString(std::move(attributedString));
localData->setTextLayoutManager(textLayoutManager_);
setLocalData(localData);
}
@ -52,7 +58,7 @@ Size ParagraphShadowNode::measure(LayoutConstraints layoutConstraints) const {
}
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
updateLocalData();
updateLocalDataIfNeeded();
ConcreteViewShadowNode::layout(layoutContext);
}

View File

@ -58,7 +58,7 @@ class ParagraphShadowNode : public ConcreteViewShadowNode<
* Creates a `LocalData` object (with `AttributedText` and
* `TextLayoutManager`) if needed.
*/
void updateLocalData();
void updateLocalDataIfNeeded();
SharedTextLayoutManager textLayoutManager_;