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_;