Fabric: Computed attributed string caching inside <Paragraph>
Summary: @public Quite trivial. We had to have this from the day one. We don't need cache invalidation policy because all subtree is immutable. Reviewed By: mdvacca Differential Revision: D8709973 fbshipit-source-id: bd7fcf0ae1dcb23894321cb5d16da18cb1ab788f
This commit is contained in:
parent
0532e01d69
commit
2c28310267
|
@ -72,4 +72,3 @@ private:
|
|||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ AttributedString BaseTextShadowNode::getAttributedString(
|
|||
const TextAttributes &textAttributes,
|
||||
const SharedShadowNodeSharedList &childNodes
|
||||
) const {
|
||||
// TODO: Implement caching.
|
||||
|
||||
AttributedString attributedString;
|
||||
|
||||
for (const auto &childNode : *childNodes) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <fabric/text/TextShadowNode.h>
|
||||
#include <fabric/textlayoutmanager/TextLayoutManager.h>
|
||||
#include <fabric/view/ConcreteViewShadowNode.h>
|
||||
#include <folly/Optional.h>
|
||||
|
||||
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<AttributedString> cachedAttributedString_ {};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
|
Loading…
Reference in New Issue