From a69bc7f1fd1f914b98beb665fc9e688673742611 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 1 Sep 2023 09:53:57 -0700 Subject: [PATCH] Simplify shadow node fragment placeholders (#39239) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../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; }