From 9c961331dda543e9b9a0d7a52c65b063f4880dd0 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 21 Nov 2018 17:10:31 -0800 Subject: [PATCH] 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 --- .../text/paragraph/ParagraphShadowNode.cpp | 12 +++++++++--- .../components/text/paragraph/ParagraphShadowNode.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp index 245dcee93..d1eba8033 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp @@ -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(getLocalData()); + if (currentLocalData && currentLocalData->getAttributedString() == attributedString) { + return; + } + auto localData = std::make_shared(); - 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); } diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h index c1d1f14df..3eb68ae14 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h @@ -58,7 +58,7 @@ class ParagraphShadowNode : public ConcreteViewShadowNode< * Creates a `LocalData` object (with `AttributedText` and * `TextLayoutManager`) if needed. */ - void updateLocalData(); + void updateLocalDataIfNeeded(); SharedTextLayoutManager textLayoutManager_;