diff --git a/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp b/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp index 11352bb9d23..60f867e1ee0 100644 --- a/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,8 @@ namespace facebook { namespace react { +thread_local LayoutContext threadLocalLayoutContext; + static void applyLayoutConstraints( YGStyle &yogaStyle, LayoutConstraints const &layoutConstraints) { @@ -332,7 +333,7 @@ void YogaLayoutableShadowNode::layoutTree( applyLayoutConstraints(yogaNode_.getStyle(), layoutConstraints); - ThreadStorage::getInstance().set(layoutContext); + threadLocalLayoutContext = layoutContext; if (layoutContext.swapLeftAndRightInRTL) { swapLeftAndRightInTree(*this); @@ -492,10 +493,8 @@ YGSize YogaLayoutableShadowNode::yogaNodeMeasureCallbackConnector( break; } - auto layoutContext = ThreadStorage::getInstance().get(); - auto size = shadowNodeRawPtr->measureContent( - layoutContext.value_or(LayoutContext{}), {minimumSize, maximumSize}); + threadLocalLayoutContext, {minimumSize, maximumSize}); return YGSize{yogaFloatFromFloat(size.width), yogaFloatFromFloat(size.height)}; diff --git a/ReactCommon/react/utils/ThreadStorage.h b/ReactCommon/react/utils/ThreadStorage.h deleted file mode 100644 index 6b391549b9c..00000000000 --- a/ReactCommon/react/utils/ThreadStorage.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -#include -#include -#include -#include - -namespace facebook { -namespace react { - -/* - * ThreadStorage is a class designed to store data for specific thread. - * When data is inserted from thread 1, it can only be retrieved from thread 1. - */ -template -class ThreadStorage { - /* - * Private default constructor. This class has to be used as a singleton. - */ - ThreadStorage() = default; - - public: - static ThreadStorage &getInstance() { - static ThreadStorage threadStorage; - return threadStorage; - } - - better::optional get() const { - std::lock_guard lock(mutex_); - auto iterator = storage_.find(std::this_thread::get_id()); - - if (iterator != storage_.end()) { - return iterator->second; - } else { - return {}; - } - } - - void set(DataT data) { - std::lock_guard lock(mutex_); - storage_[std::this_thread::get_id()] = data; - } - - private: - mutable std::mutex mutex_; - better::map storage_; -}; - -} // namespace react -} // namespace facebook