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
This commit is contained in:
Valentin Shergin 2018-08-04 09:30:10 -07:00 committed by Facebook Github Bot
parent da6a5e0439
commit 5d0b51b107
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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<bool> sealed_ {false};
};
#endif
} // namespace react
} // namespace facebook