From 3770d4df45b37720e318669496c006fb6e72a3d7 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sat, 4 Aug 2018 09:30:32 -0700 Subject: [PATCH] Fabric: Using `const &` type for `ShadowNodeFragment`'s fields Summary: @public To avoid unnecessary copying of `shared_ptr`s inside ShadowNodeFragment, now we store them as `const &` references. Reviewed By: mdvacca Differential Revision: D8988388 fbshipit-source-id: 0b3582e57ce7577b8fa819392bf33f34e1a60b59 --- .../components/view/ConcreteViewShadowNode.h | 1 + .../ConcreteComponentDescriptor.h | 2 + .../fabric/core/shadownode/ShadowNode.cpp | 1 + .../fabric/core/shadownode/ShadowNode.h | 11 +---- .../core/shadownode/ShadowNodeFragment.cpp | 34 +++++++++++++++ .../core/shadownode/ShadowNodeFragment.h | 42 +++++++++++++++++++ .../fabric/uimanager/FabricUIManager.cpp | 1 + 7 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 ReactCommon/fabric/core/shadownode/ShadowNodeFragment.cpp create mode 100644 ReactCommon/fabric/core/shadownode/ShadowNodeFragment.h diff --git a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h index fb1228b75..209a85940 100644 --- a/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h +++ b/ReactCommon/fabric/components/view/ConcreteViewShadowNode.h @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace facebook { diff --git a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h index 31a0fb623..0ec1cba19 100644 --- a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h +++ b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 9fdb725af..2fc759237 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -9,6 +9,7 @@ #include +#include #include #include diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index 762f1ef7e..dca542b3f 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -21,6 +21,8 @@ namespace facebook { namespace react { +struct ShadowNodeFragment; + class ShadowNode; using SharedShadowNode = std::shared_ptr; @@ -29,15 +31,6 @@ using SharedShadowNodeList = std::vector>; using SharedShadowNodeSharedList = std::shared_ptr; using SharedShadowNodeUnsharedList = std::shared_ptr; -struct ShadowNodeFragment { - Tag tag; - Tag rootTag; - SharedProps props; - SharedEventEmitter eventEmitter; - SharedShadowNodeSharedList children; - SharedLocalData localData; -}; - using ShadowNodeCloneFunction = std::function +#include +#include +#include +#include + +namespace facebook { +namespace react { + +/* + * An object which supposed to be used as a parameter specifying a shape + * of created or cloned ShadowNode. + * Note: Most of the fields are `const &` references (essentially just raw + * pointers) which means that the Fragment does not copy/store them or + * retain ownership of them. + */ +struct ShadowNodeFragment { + Tag tag = 0; + Tag rootTag = 0; + const SharedProps &props = nullSharedProps(); + const SharedEventEmitter &eventEmitter = nullSharedEventEmitter(); + const SharedShadowNodeSharedList &children = nullSharedChildren(); + const SharedLocalData &localData = nullLocalData(); + +private: + static SharedProps &nullSharedProps(); + static SharedEventEmitter &nullSharedEventEmitter(); + static SharedShadowNodeSharedList &nullSharedChildren(); + static SharedLocalData &nullLocalData(); +}; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 1ecd1b25b..11f6b362d 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include