From 05862faab478bad880d305f40e681c2011edfcc5 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 16 Oct 2019 17:51:09 -0700 Subject: [PATCH] Farbic: Making `ShadowNode::revision_` debug only Summary: We use this piece of data only for debug purposes, so there is no need to pay for that in prod. Changelog: [Internal] - Small optimization in `ShadowNode` (Fabric) Reviewed By: JoshuaGross Differential Revision: D17961209 fbshipit-source-id: 2a0d609ac4d3c4815b26789551a4c51bcf91dea4 --- .../fabric/core/shadownode/ShadowNode.cpp | 18 ++++++++++++------ .../fabric/core/shadownode/ShadowNode.h | 14 +++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 826c2c8a297..ff105215be2 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -34,7 +34,11 @@ bool ShadowNode::sameFamily(const ShadowNode &first, const ShadowNode &second) { ShadowNode::ShadowNode( const ShadowNodeFragment &fragment, const ComponentDescriptor &componentDescriptor) - : props_(fragment.props), + : +#if RN_DEBUG_STRING_CONVERTIBLE + revision_(1), +#endif + props_(fragment.props), children_( fragment.children ? fragment.children : emptySharedShadowNodeSharedList()), @@ -44,8 +48,7 @@ ShadowNode::ShadowNode( fragment.surfaceId, fragment.eventEmitter, componentDescriptor)), - childrenAreShared_(true), - revision_(1) { + childrenAreShared_(true) { assert(props_); assert(children_); @@ -57,7 +60,11 @@ ShadowNode::ShadowNode( ShadowNode::ShadowNode( const ShadowNode &sourceShadowNode, const ShadowNodeFragment &fragment) - : props_(fragment.props ? fragment.props : sourceShadowNode.props_), + : +#if RN_DEBUG_STRING_CONVERTIBLE + revision_(sourceShadowNode.revision_ + 1), +#endif + props_(fragment.props ? fragment.props : sourceShadowNode.props_), children_( fragment.children ? fragment.children : sourceShadowNode.children_), localData_( @@ -67,8 +74,7 @@ ShadowNode::ShadowNode( fragment.state ? fragment.state : sourceShadowNode.getMostRecentState()), family_(sourceShadowNode.family_), - childrenAreShared_(true), - revision_(sourceShadowNode.revision_ + 1) { + childrenAreShared_(true) { // `tag`, `surfaceId`, and `eventEmitter` cannot be changed with cloning. assert(fragment.tag == ShadowNodeFragment::tagPlaceholder()); assert(fragment.surfaceId == ShadowNodeFragment::surfaceIdPlaceholder()); diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index b2e439dbf0b..61fc8056bf4 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -169,6 +169,13 @@ class ShadowNode : public virtual Sealable, std::string getDebugValue() const override; SharedDebugStringConvertibleList getDebugChildren() const override; SharedDebugStringConvertibleList getDebugProps() const override; + + /* + * A number of the generation of the ShadowNode instance; + * is used and useful for debug-printing purposes *only*. + * Do not access this value in any circumstances. + */ + int const revision_; #endif protected: @@ -194,13 +201,6 @@ class ShadowNode : public virtual Sealable, * to be cloned before the first mutation. */ bool childrenAreShared_; - - /* - * A number of the generation of the ShadowNode instance; - * is used and useful for debug-printing purposes *only*. - * Do not access this value in any circumstances. - */ - const int revision_; }; } // namespace react