Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@ ComponentDescriptorProviderRegistry::createComponentDescriptorRegistry(
auto registry = std::make_shared<const ComponentDescriptorRegistry>(
parameters, *this, parameters.contextContainer);

// for (const auto& pair : componentDescriptorProviders_) {
// registry->add(pair.second);
// }

std::vector<ComponentDescriptorProvider> providers;
providers.reserve(componentDescriptorProviders_.size());
for (const auto& pair : componentDescriptorProviders_) {
registry->add(pair.second);
providers.push_back(pair.second);
}

// 2) enqueue async add
registry->addMultipleAsync(std::move(providers));

componentDescriptorRegistries_.push_back(registry);

return registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,34 @@ ComponentDescriptorRegistry::ComponentDescriptorRegistry(
providerRegistry_(providerRegistry),
contextContainer_(std::move(contextContainer)) {}

void ComponentDescriptorRegistry::addMultipleAsync(
std::vector<ComponentDescriptorProvider> providers) const {
Comment on lines +30 to +31
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: do we want to make this a rvalue reference && to make obvious that the function wants to take ownvership?

// Copy everything we need before the thread starts
auto parametersCopy = parameters_;
auto contextContainerCopy = contextContainer_;

// Start thread immediately
std::thread([this, providers = std::move(providers), parametersCopy, contextContainerCopy]() {
std::unique_lock lock(mutex_);

for (const auto& provider : providers) {
auto componentDescriptor = provider.constructor(
{parametersCopy.eventDispatcher,
contextContainerCopy,
provider.flavor});

react_native_assert(componentDescriptor->getComponentHandle() == provider.handle);
react_native_assert(componentDescriptor->getComponentName() == provider.name);

auto sharedComponentDescriptor =
std::shared_ptr<const ComponentDescriptor>(std::move(componentDescriptor));

_registryByHandle[provider.handle] = sharedComponentDescriptor;
_registryByName[provider.name] = sharedComponentDescriptor;
}
}).detach();
}

void ComponentDescriptorRegistry::add(
ComponentDescriptorProvider componentDescriptorProvider) const {
std::unique_lock lock(mutex_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/core/InstanceHandle.h>
#include <react/utils/ContextContainer.h>
#include <thread>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: as we only need that in the implementaton lets move it to the cpp file to keep the header clean?


namespace facebook::react {

Expand All @@ -40,6 +41,8 @@ class ComponentDescriptorRegistry {
const ComponentDescriptorProviderRegistry& providerRegistry,
ContextContainer::Shared contextContainer);

void addMultipleAsync(std::vector<ComponentDescriptorProvider> providers) const;

/*
* This is broken. Please do not use.
* If you requesting a ComponentDescriptor and unsure that it's there, you are
Expand Down
Loading