Skip to content

Commit

Permalink
Remove folly::F14FastSet from React Native (#39490)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Sep 17, 2023
1 parent 3bc402f commit d7d030a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -60,7 +60,7 @@ void RCTInstallNativeComponentRegistryBinding(facebook::jsi::Runtime &runtime)

@implementation RCTComponentViewFactory {
butter::map<ComponentHandle, RCTComponentViewClassDescriptor> _componentViewClasses;
butter::set<std::string> _registeredComponentsNames;
std::unordered_set<std::string> _registeredComponentsNames;
ComponentDescriptorProviderRegistry _providerRegistry;
std::shared_mutex _mutex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -40,6 +40,6 @@ class RCTMountingTransactionObserverCoordinator final {
private:
facebook::butter::map<
facebook::react::SurfaceId,
facebook::butter::set<RCTComponentViewDescriptor>>
std::unordered_set<RCTComponentViewDescriptor>>
registry_;
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cfenv>
#include <cmath>
#include <unordered_set>
#include <vector>

namespace facebook::react {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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};
Expand Down
38 changes: 0 additions & 38 deletions packages/react-native/ReactCommon/butter/set.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -20,6 +19,7 @@
#include <react/renderer/uimanager/UIManagerAnimationDelegate.h>

#include <optional>
#include <unordered_set>

namespace facebook::react {

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7d030a

Please sign in to comment.