From 3827c96a0256b06d536e040cc928a6508eee8cab Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 1 Sep 2023 07:37:37 -0700 Subject: [PATCH] Simplify shadow node fragment placeholders (#39239) Summary: 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 --- .../react/renderer/core/ShadowNodeFragment.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFragment.cpp b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFragment.cpp index 36c7ad98c0812f..69a28388460895 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFragment.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/ShadowNodeFragment.cpp @@ -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; }