From d7d030a2cd1cdef01947678cb05474178aefeef1 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Sat, 16 Sep 2023 17:29:09 -0700 Subject: [PATCH] Remove folly::F14FastSet from React Native (#39490) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39490 changelog: [internal] Removing use of folly::F14FastSet to reduce the dependency on Folly library. Reviewed By: rshest Differential Revision: D48967273 fbshipit-source-id: 6b67e674667b13ce8c9a80b2b1682f0b120c71ac --- .../Mounting/RCTComponentViewFactory.mm | 4 +- ...CTMountingTransactionObserverCoordinator.h | 4 +- .../react/fabric/FabricMountingManager.cpp | 15 ++++---- .../jni/react/fabric/FabricMountingManager.h | 4 +- .../react-native/ReactCommon/butter/set.h | 38 ------------------- .../LayoutAnimationKeyFrameManager.cpp | 9 +++-- .../LayoutAnimationKeyFrameManager.h | 4 +- 7 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 packages/react-native/ReactCommon/butter/set.h diff --git a/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm b/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm index bf0f682730b355..83bbb58a3e8571 100644 --- a/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm +++ b/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm @@ -12,8 +12,8 @@ #import #import -#import #import +#import #import #import @@ -60,7 +60,7 @@ void RCTInstallNativeComponentRegistryBinding(facebook::jsi::Runtime &runtime) @implementation RCTComponentViewFactory { butter::map _componentViewClasses; - butter::set _registeredComponentsNames; + std::unordered_set _registeredComponentsNames; ComponentDescriptorProviderRegistry _providerRegistry; std::shared_mutex _mutex; } diff --git a/packages/react-native/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h b/packages/react-native/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h index b1a6346bb396be..317390536f9fb4 100644 --- a/packages/react-native/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h +++ b/packages/react-native/React/Fabric/Mounting/RCTMountingTransactionObserverCoordinator.h @@ -6,10 +6,10 @@ */ #import +#import #import "RCTMountingTransactionObserverCoordinator.h" #import -#import #include @@ -40,6 +40,6 @@ class RCTMountingTransactionObserverCoordinator final { private: facebook::butter::map< facebook::react::SurfaceId, - facebook::butter::set> + std::unordered_set> registry_; }; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index 2136779d78c965..75c42d6c5f4d7f 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace facebook::react { @@ -48,7 +49,7 @@ FabricMountingManager::FabricMountingManager( void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) { std::lock_guard lock(allocatedViewsMutex_); - allocatedViewRegistry_.emplace(surfaceId, butter::set{}); + allocatedViewRegistry_.emplace(surfaceId, std::unordered_set{}); } void FabricMountingManager::onSurfaceStop(SurfaceId surfaceId) { @@ -261,12 +262,12 @@ void FabricMountingManager::executeMount( std::lock_guard allocatedViewsLock(allocatedViewsMutex_); auto allocatedViewsIterator = allocatedViewRegistry_.find(surfaceId); - auto defaultAllocatedViews = butter::set{}; - // Do not remove `defaultAllocatedViews` or initialize `butter::set{}` - // inline in below ternary expression - - // if falsy operand is a value type, the compiler will decide the expression - // to be a value type, an unnecessary (sometimes expensive) copy will happen - // as a result. + auto defaultAllocatedViews = std::unordered_set{}; + // Do not remove `defaultAllocatedViews` or initialize + // `std::unordered_set{}` inline in below ternary expression - if falsy + // operand is a value type, the compiler will decide the expression to be a + // value type, an unnecessary (sometimes expensive) copy will happen as a + // result. const auto& allocatedViewTags = allocatedViewsIterator != allocatedViewRegistry_.end() ? allocatedViewsIterator->second diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h index 400f6cadf180f8..0edc461a0bd74f 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.h @@ -8,8 +8,8 @@ #pragma once #include +#include -#include #include #include #include @@ -58,7 +58,7 @@ class FabricMountingManager final { std::recursive_mutex commitMutex_; - butter::map> allocatedViewRegistry_{}; + butter::map> allocatedViewRegistry_{}; std::recursive_mutex allocatedViewsMutex_; const bool reduceDeleteCreateMutation_{false}; diff --git a/packages/react-native/ReactCommon/butter/set.h b/packages/react-native/ReactCommon/butter/set.h deleted file mode 100644 index 254bf88e47c3ea..00000000000000 --- a/packages/react-native/ReactCommon/butter/set.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and 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 - -#ifdef BUTTER_USE_FOLLY_CONTAINERS - -#include - -#else - -#include - -#endif - -namespace facebook { -namespace butter { - -#ifdef BUTTER_USE_FOLLY_CONTAINERS - -template -using set = folly::F14FastSet; - -#else - -template -using set = std::unordered_set; - -#endif - -} // namespace butter -} // namespace facebook diff --git a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp index a46987977b2f32..1720c23d5e0ff2 100644 --- a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.cpp @@ -264,9 +264,10 @@ LayoutAnimationKeyFrameManager::pullTransaction( // TODO: to prevent this step we could tag Remove/Insert mutations as // being moves on the Differ level, since we know that there? We could use // TinyMap here, but it's not exposed by Differentiator (yet). - butter::set insertedTags; - butter::set deletedTags; - butter::set reparentedTags; // tags that are deleted and recreated + std::unordered_set insertedTags; + std::unordered_set deletedTags; + std::unordered_set + reparentedTags; // tags that are deleted and recreated std::unordered_map movedTags; for (const auto& mutation : mutations) { if (mutation.type == ShadowViewMutation::Type::Insert) { @@ -1630,7 +1631,7 @@ void LayoutAnimationKeyFrameManager::deleteAnimationsForStoppedSurfaces() // Execute stopSurface on any ongoing animations if (inflightAnimationsExistInitially) { - butter::set surfaceIdsToStop{}; + std::unordered_set surfaceIdsToStop{}; { std::scoped_lock lock(surfaceIdsToStopMutex_); surfaceIdsToStop = surfaceIdsToStop_; diff --git a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h index d1eeb7351a8a8e..1ee64f871f0614 100644 --- a/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h +++ b/packages/react-native/ReactCommon/react/renderer/animations/LayoutAnimationKeyFrameManager.h @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include +#include namespace facebook::react { @@ -144,7 +144,7 @@ class LayoutAnimationKeyFrameManager : public UIManagerAnimationDelegate, mutable std::mutex layoutAnimationStatusDelegateMutex_; mutable LayoutAnimationStatusDelegate* layoutAnimationStatusDelegate_{}; mutable std::mutex surfaceIdsToStopMutex_; - mutable butter::set surfaceIdsToStop_{}; + mutable std::unordered_set surfaceIdsToStop_{}; bool reduceDeleteCreateMutation_{false}; // Function that returns current time in milliseconds