From 5d0b51b107726c31b32db21f07b986aa0c94de54 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sat, 4 Aug 2018 09:30:10 -0700 Subject: [PATCH] Fabric: Making Sealable debug-only thing Summary: @public Now, Sealable is already error-preventing-only mechanism, no business logic relies on that. So, it makes sense to make it debug-only to illuminate possible performance impact. Reviewed By: mdvacca Differential Revision: D8923597 fbshipit-source-id: 80aa9097c4b719e91de73ac59f38d3a4751f0b06 --- ReactCommon/fabric/core/primitives/Sealable.cpp | 6 +++++- ReactCommon/fabric/core/primitives/Sealable.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/core/primitives/Sealable.cpp b/ReactCommon/fabric/core/primitives/Sealable.cpp index a44181ee1..ffb1332d3 100644 --- a/ReactCommon/fabric/core/primitives/Sealable.cpp +++ b/ReactCommon/fabric/core/primitives/Sealable.cpp @@ -24,6 +24,8 @@ namespace react { * http://en.cppreference.com/w/cpp/language/rule_of_three */ +#ifndef NDEBUG + Sealable::Sealable(): sealed_(false) {} Sealable::Sealable(const Sealable &other): sealed_(false) {}; @@ -40,7 +42,7 @@ Sealable &Sealable::operator=(const Sealable &other) { Sealable &Sealable::operator=(Sealable &&other) noexcept { ensureUnsealed(); return *this; -}; +} void Sealable::seal() const { sealed_ = true; @@ -56,5 +58,7 @@ void Sealable::ensureUnsealed() const { } } +#endif + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/core/primitives/Sealable.h b/ReactCommon/fabric/core/primitives/Sealable.h index 8cc3c6ed9..7454c373b 100644 --- a/ReactCommon/fabric/core/primitives/Sealable.h +++ b/ReactCommon/fabric/core/primitives/Sealable.h @@ -40,6 +40,18 @@ namespace react { * 3. Call `seal()` at some point from which any modifications * must be prevented. */ + +#ifdef NDEBUG + +class Sealable { +public: + inline void seal() const {} + inline bool getSealed() const { return true; } + inline void ensureUnsealed() const {} +}; + +#else + class Sealable { public: Sealable(); @@ -70,5 +82,7 @@ private: mutable std::atomic sealed_ {false}; }; +#endif + } // namespace react } // namespace facebook