From 1f969d34404175c04eb5a579b6bb886c8493c170 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 10 Apr 2018 12:45:30 -0700 Subject: [PATCH] Fabric: Equality operators for ShadowNode Summary: Test for equality will be used in ShadowNode Tree Diffing algorithm. Reviewed By: fkgozali Differential Revision: D7467802 fbshipit-source-id: 5383add9fc7d7e4a772ca16e70a54f7e0c36823a --- ReactCommon/fabric/core/shadownode/ShadowNode.cpp | 15 +++++++++++++++ ReactCommon/fabric/core/shadownode/ShadowNode.h | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 2313be859..c2da0db17 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -116,6 +116,21 @@ void ShadowNode::clearSourceNode() { sourceNode_.reset(); } +#pragma mark - Equality + +bool ShadowNode::operator==(const ShadowNode& rhs) const { + // Note: Child nodes are not considered as part of instance's value + // and/or identity. + return + tag_ == rhs.tag_ && + rootTag_ == rhs.rootTag_ && + props_ == rhs.props_; +} + +bool ShadowNode::operator!=(const ShadowNode& rhs) const { + return !(*this == rhs); +} + #pragma mark - DebugStringConvertible std::string ShadowNode::getDebugName() const { diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index 2efadda40..f03acb107 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -67,6 +67,18 @@ public: void replaceChild(const SharedShadowNode &oldChild, const SharedShadowNode &newChild); void clearSourceNode(); +#pragma mark - Equality + + /* + * Equality operators. + * Use this to compare `ShadowNode`s values for equality (and non-equality). + * Same values indicates that nodes must not produce mutation instructions + * during tree diffing process. + * Child nodes are not considered as part of the value. + */ + virtual bool operator==(const ShadowNode& rhs) const; + virtual bool operator!=(const ShadowNode& rhs) const; + #pragma mark - DebugStringConvertible std::string getDebugName() const override;