diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 07cc47603e4..4fa5ac9b466 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -72,4 +72,3 @@ private: } // namespace react } // namespace facebook - diff --git a/ReactCommon/fabric/text/basetext/BaseTextShadowNode.cpp b/ReactCommon/fabric/text/basetext/BaseTextShadowNode.cpp index f2f2d08a7ee..ec97f412444 100644 --- a/ReactCommon/fabric/text/basetext/BaseTextShadowNode.cpp +++ b/ReactCommon/fabric/text/basetext/BaseTextShadowNode.cpp @@ -20,8 +20,6 @@ AttributedString BaseTextShadowNode::getAttributedString( const TextAttributes &textAttributes, const SharedShadowNodeSharedList &childNodes ) const { - // TODO: Implement caching. - AttributedString attributedString; for (const auto &childNode : *childNodes) { diff --git a/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.cpp index e7b6513ba23..99222fc317f 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.cpp @@ -19,7 +19,12 @@ ComponentName ParagraphShadowNode::getComponentName() const { } AttributedString ParagraphShadowNode::getAttributedString() const { - return BaseTextShadowNode::getAttributedString(getProps()->textAttributes, getChildren()); + if (!cachedAttributedString_.has_value()) { + cachedAttributedString_ = + BaseTextShadowNode::getAttributedString(getProps()->textAttributes, getChildren()); + } + + return cachedAttributedString_.value(); } void ParagraphShadowNode::setTextLayoutManager(SharedTextLayoutManager textLayoutManager) { diff --git a/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.h b/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.h index df16aee1b79..f7b1ea4fd2a 100644 --- a/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.h +++ b/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace facebook { namespace react { @@ -63,6 +64,12 @@ private: void updateLocalData(); SharedTextLayoutManager textLayoutManager_; + + /* + * Cached attributed string that represents the content of the subtree started + * from the node. + */ + mutable folly::Optional cachedAttributedString_ {}; }; } // namespace react