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
This commit is contained in:
Samuel Susla
2023-09-16 17:29:09 -07:00
committed by Facebook GitHub Bot
parent 3bc402f612
commit d7d030a2cd
7 changed files with 21 additions and 57 deletions
@@ -12,8 +12,8 @@
#import <React/RCTLog.h>
#import <butter/map.h>
#import <butter/set.h>
#import <shared_mutex>
#import <unordered_set>
#import <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#import <react/renderer/componentregistry/componentNameByReactViewName.h>
@@ -60,7 +60,7 @@ static Class<RCTComponentViewProtocol> RCTComponentViewClassWithName(const char
@implementation RCTComponentViewFactory {
butter::map<ComponentHandle, RCTComponentViewClassDescriptor> _componentViewClasses;
butter::set<std::string> _registeredComponentsNames;
std::unordered_set<std::string> _registeredComponentsNames;
ComponentDescriptorProviderRegistry _providerRegistry;
std::shared_mutex _mutex;
}
@@ -6,10 +6,10 @@
*/
#import <React/RCTComponentViewDescriptor.h>
#import <unordered_set>
#import "RCTMountingTransactionObserverCoordinator.h"
#import <butter/map.h>
#import <butter/set.h>
#include <react/renderer/mounting/MountingTransaction.h>
@@ -40,6 +40,6 @@ class RCTMountingTransactionObserverCoordinator final {
private:
facebook::butter::map<
facebook::react::SurfaceId,
facebook::butter::set<RCTComponentViewDescriptor>>
std::unordered_set<RCTComponentViewDescriptor>>
registry_;
};
@@ -25,6 +25,7 @@
#include <cfenv>
#include <cmath>
#include <unordered_set>
#include <vector>
namespace facebook::react {
@@ -48,7 +49,7 @@ FabricMountingManager::FabricMountingManager(
void FabricMountingManager::onSurfaceStart(SurfaceId surfaceId) {
std::lock_guard lock(allocatedViewsMutex_);
allocatedViewRegistry_.emplace(surfaceId, butter::set<Tag>{});
allocatedViewRegistry_.emplace(surfaceId, std::unordered_set<Tag>{});
}
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<Tag>{};
// Do not remove `defaultAllocatedViews` or initialize `butter::set<Tag>{}`
// 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<Tag>{};
// Do not remove `defaultAllocatedViews` or initialize
// `std::unordered_set<Tag>{}` 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
@@ -8,8 +8,8 @@
#pragma once
#include <mutex>
#include <unordered_set>
#include <butter/set.h>
#include <fbjni/fbjni.h>
#include <react/fabric/JFabricUIManager.h>
#include <react/renderer/uimanager/primitives.h>
@@ -58,7 +58,7 @@ class FabricMountingManager final {
std::recursive_mutex commitMutex_;
butter::map<SurfaceId, butter::set<Tag>> allocatedViewRegistry_{};
butter::map<SurfaceId, std::unordered_set<Tag>> allocatedViewRegistry_{};
std::recursive_mutex allocatedViewsMutex_;
const bool reduceDeleteCreateMutation_{false};
@@ -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 <butter/butter.h>
#ifdef BUTTER_USE_FOLLY_CONTAINERS
#include <folly/container/F14Set.h>
#else
#include <unordered_set>
#endif
namespace facebook {
namespace butter {
#ifdef BUTTER_USE_FOLLY_CONTAINERS
template <typename... Ts>
using set = folly::F14FastSet<Ts...>;
#else
template <typename... Ts>
using set = std::unordered_set<Ts...>;
#endif
} // namespace butter
} // namespace facebook
@@ -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<Tag> insertedTags;
butter::set<Tag> deletedTags;
butter::set<Tag> reparentedTags; // tags that are deleted and recreated
std::unordered_set<Tag> insertedTags;
std::unordered_set<Tag> deletedTags;
std::unordered_set<Tag>
reparentedTags; // tags that are deleted and recreated
std::unordered_map<Tag, ShadowViewMutation> 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<SurfaceId> surfaceIdsToStop{};
std::unordered_set<SurfaceId> surfaceIdsToStop{};
{
std::scoped_lock lock(surfaceIdsToStopMutex_);
surfaceIdsToStop = surfaceIdsToStop_;
@@ -8,7 +8,6 @@
#pragma once
#include <ReactCommon/RuntimeExecutor.h>
#include <butter/set.h>
#include <react/renderer/animations/LayoutAnimationCallbackWrapper.h>
#include <react/renderer/animations/primitives.h>
#include <react/renderer/core/RawValue.h>
@@ -20,6 +19,7 @@
#include <react/renderer/uimanager/UIManagerAnimationDelegate.h>
#include <optional>
#include <unordered_set>
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<SurfaceId> surfaceIdsToStop_{};
mutable std::unordered_set<SurfaceId> surfaceIdsToStop_{};
bool reduceDeleteCreateMutation_{false};
// Function that returns current time in milliseconds