Skip to content

Commit

Permalink
Simplify shadow node fragment placeholders (#39239)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #39239

We can avoid static guards and heap allocation memory by forcing a default initialized shared_ptr (which is constexpr), and telling the compiler to not bother with registering a destructor, as these shared_ptr will never hold a value.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48867013

fbshipit-source-id: c31f535bb19382878c9f21d7145188bd91b63265
  • Loading branch information
javache authored and facebook-github-bot committed Sep 1, 2023
1 parent 2b98cda commit a69bc7f
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@

namespace facebook::react {

#if defined(__clang__)
#define NO_DESTROY [[clang::no_destroy]]
#else
#define NO_DESTROY
#endif

const Props::Shared &ShadowNodeFragment::propsPlaceholder() {
static auto &instance = *new Props::Shared();
NO_DESTROY static Props::Shared instance;
return instance;
}

const ShadowNode::SharedListOfShared &
ShadowNodeFragment::childrenPlaceholder() {
static auto &instance = *new ShadowNode::SharedListOfShared();
NO_DESTROY static ShadowNode::SharedListOfShared instance;
return instance;
}

const State::Shared &ShadowNodeFragment::statePlaceholder() {
static auto &instance = *new State::Shared();
NO_DESTROY static State::Shared instance;
return instance;
}

Expand Down

0 comments on commit a69bc7f

Please sign in to comment.