Fabric: Changes in `BaseTextShadowNode` to remove usage of `shared_from_this()`

Summary:
This is another step on the journey of removing `enable_shared_from_this`.

It's unclear why we used that before but it's clear now that using shared_ptr here is not necessary because all computation around happens inside the single callstack, so by definition we don't have object life-time concerns here.

Changelog: [Internal] Small Fabric-specific optimization.

Reviewed By: sammy-SC

Differential Revision: D17973957

fbshipit-source-id: 09a65c78e22083ed21b041240307f4858379cc60
This commit is contained in:
Valentin Shergin 2019-10-21 09:42:43 -07:00 коммит произвёл Facebook Github Bot
Родитель c5f704b8e3
Коммит 7186a65b13
4 изменённых файлов: 10 добавлений и 11 удалений

Просмотреть файл

@ -18,11 +18,11 @@ namespace facebook {
namespace react {
AttributedString BaseTextShadowNode::getAttributedString(
const TextAttributes &textAttributes,
const SharedShadowNode &parentNode) {
TextAttributes const &textAttributes,
ShadowNode const &parentNode) {
auto attributedString = AttributedString{};
for (const auto &childNode : parentNode->getChildren()) {
for (auto const &childNode : parentNode.getChildren()) {
// RawShadowNode
auto rawTextShadowNode =
std::dynamic_pointer_cast<const RawTextShadowNode>(childNode);
@ -35,7 +35,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
// `attributedString` causes a retain cycle (besides that fact that we
// don't need it at all). Storing a `ShadowView` instance instead of
// `ShadowNode` should properly fix this problem.
fragment.parentShadowView = ShadowView(*parentNode);
fragment.parentShadowView = ShadowView(parentNode);
attributedString.appendFragment(fragment);
continue;
}
@ -48,7 +48,7 @@ AttributedString BaseTextShadowNode::getAttributedString(
localTextAttributes.apply(textShadowNode->getProps()->textAttributes);
attributedString.appendAttributedString(
textShadowNode->getAttributedString(
localTextAttributes, textShadowNode));
localTextAttributes, *textShadowNode));
continue;
}

Просмотреть файл

@ -27,8 +27,8 @@ class BaseTextShadowNode {
* function, or if TextInput should inherit from BaseTextShadowNode.
*/
static AttributedString getAttributedString(
const TextAttributes &baseTextAttributes,
const SharedShadowNode &parentNode);
TextAttributes const &baseTextAttributes,
ShadowNode const &parentNode);
};
} // namespace react

Просмотреть файл

@ -19,8 +19,8 @@ AttributedString ParagraphShadowNode::getAttributedString() const {
auto textAttributes = TextAttributes::defaultTextAttributes();
textAttributes.apply(getProps()->textAttributes);
cachedAttributedString_ = BaseTextShadowNode::getAttributedString(
textAttributes, shared_from_this());
cachedAttributedString_ =
BaseTextShadowNode::getAttributedString(textAttributes, *this);
}
return cachedAttributedString_.value();

Просмотреть файл

@ -35,8 +35,7 @@ AttributedString AndroidTextInputShadowNode::getAttributedString() const {
textAttributes.apply(getProps()->textAttributes);
// Use BaseTextShadowNode to get attributed string from children
return BaseTextShadowNode::getAttributedString(
textAttributes, shared_from_this());
return BaseTextShadowNode::getAttributedString(textAttributes, *this);
}
#pragma mark - LayoutableShadowNode