Skip to content

Commit

Permalink
Pass string by ref in TurboModule lookup path
Browse files Browse the repository at this point in the history
Summary:
Avoid unnecessary string copies

Changelog: [internal]

Reviewed By: nlutsenko

Differential Revision: D36312750

fbshipit-source-id: caf0985f988eb497de3be3c0526809593b01a9e2
  • Loading branch information
javache authored and facebook-github-bot committed May 13, 2022
1 parent 51e029e commit 3337add
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ void CompositeTurboModuleManagerDelegate::registerNatives() {

std::shared_ptr<TurboModule>
CompositeTurboModuleManagerDelegate::getTurboModule(
const std::string moduleName,
const std::shared_ptr<CallInvoker> jsInvoker) {
const std::string &moduleName,
const std::shared_ptr<CallInvoker> &jsInvoker) {
for (auto delegate : mDelegates_) {
if (auto turboModule = delegate->getTurboModule(moduleName, jsInvoker)) {
return turboModule;
Expand All @@ -39,7 +39,7 @@ CompositeTurboModuleManagerDelegate::getTurboModule(

std::shared_ptr<TurboModule>
CompositeTurboModuleManagerDelegate::getTurboModule(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params) {
for (auto delegate : mDelegates_) {
if (auto turboModule = delegate->getTurboModule(moduleName, params)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class CompositeTurboModuleManagerDelegate
static void registerNatives();

std::shared_ptr<TurboModule> getTurboModule(
const std::string moduleName,
const std::shared_ptr<CallInvoker> jsInvoker) override;
const std::string &moduleName,
const std::shared_ptr<CallInvoker> &jsInvoker) override;
std::shared_ptr<TurboModule> getTurboModule(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params) override;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class TurboModuleManagerDelegate
"Lcom/facebook/react/turbomodule/core/TurboModuleManagerDelegate;";

virtual std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::string &name,
const JavaTurboModule::InitParams &params) = 0;
virtual std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::shared_ptr<CallInvoker> jsInvoker) = 0;
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) = 0;

private:
friend HybridBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(
}

std::shared_ptr<TurboModule> SampleTurboModuleSpec_ModuleProvider(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params) {
if (moduleName == "SampleTurboModule") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JSI_EXPORT NativeSampleTurboModuleSpecJSI : public JavaTurboModule {
};

std::shared_ptr<TurboModule> SampleTurboModuleSpec_ModuleProvider(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params);

} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace react {
${modules}
std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
${moduleLookups.map(ModuleLookupTemplate).join('\n')}
return nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace react {
${modules}
std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> ${libraryName}_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
}
std::shared_ptr<TurboModule> SampleWithUppercaseName_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> SampleWithUppercaseName_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"SampleTurboModule\\") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
methodMap_[\\"getNullableArray\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModuleSpecJSI_getNullableArray};
}
std::shared_ptr<TurboModule> complex_objects_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> complex_objects_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"SampleTurboModule\\") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
}
std::shared_ptr<TurboModule> empty_native_modules_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> empty_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"SampleTurboModule\\") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ AliasTurboModuleSpecJSI::AliasTurboModuleSpecJSI(const JavaTurboModule::InitPara
methodMap_[\\"cropImage\\"] = MethodMetadata {1, __hostFunction_AliasTurboModuleSpecJSI_cropImage};
}
std::shared_ptr<TurboModule> native_modules_with_type_aliases_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> native_modules_with_type_aliases_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"AliasTurboModule\\") {
return std::make_shared<AliasTurboModuleSpecJSI>(params);
}
Expand Down Expand Up @@ -250,7 +250,7 @@ NativeExceptionsManagerSpecJSI::NativeExceptionsManagerSpecJSI(const JavaTurboMo
methodMap_[\\"dismissRedbox\\"] = MethodMetadata {0, __hostFunction_NativeExceptionsManagerSpecJSI_dismissRedbox};
}
std::shared_ptr<TurboModule> real_module_example_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> real_module_example_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"CameraRollManager\\") {
return std::make_shared<NativeCameraRollManagerSpecJSI>(params);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ NativeSampleTurboModuleSpecJSI::NativeSampleTurboModuleSpecJSI(const JavaTurboMo
methodMap_[\\"getValueWithPromise\\"] = MethodMetadata {1, __hostFunction_NativeSampleTurboModuleSpecJSI_getValueWithPromise};
}
std::shared_ptr<TurboModule> simple_native_modules_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> simple_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"SampleTurboModule\\") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
Expand Down Expand Up @@ -391,7 +391,7 @@ NativeSampleTurboModule2SpecJSI::NativeSampleTurboModule2SpecJSI(const JavaTurbo
methodMap_[\\"voidFunc\\"] = MethodMetadata {0, __hostFunction_NativeSampleTurboModule2SpecJSI_voidFunc};
}
std::shared_ptr<TurboModule> two_modules_different_files_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params) {
std::shared_ptr<TurboModule> two_modules_different_files_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
if (moduleName == \\"SampleTurboModule\\") {
return std::make_shared<NativeSampleTurboModuleSpecJSI>(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public:
};
std::shared_ptr<TurboModule> SampleWithUppercaseName_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> SampleWithUppercaseName_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -139,7 +139,7 @@ public:
};
std::shared_ptr<TurboModule> complex_objects_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> complex_objects_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -248,7 +248,7 @@ public:
};
std::shared_ptr<TurboModule> empty_native_modules_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> empty_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -357,7 +357,7 @@ public:
};
std::shared_ptr<TurboModule> native_modules_with_type_aliases_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> native_modules_with_type_aliases_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -474,7 +474,7 @@ public:
};
std::shared_ptr<TurboModule> real_module_example_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> real_module_example_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -583,7 +583,7 @@ public:
};
std::shared_ptr<TurboModule> simple_native_modules_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> simple_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down Expand Up @@ -700,7 +700,7 @@ public:
};
std::shared_ptr<TurboModule> two_modules_different_files_ModuleProvider(const std::string moduleName, const JavaTurboModule::InitParams &params);
std::shared_ptr<TurboModule> two_modules_different_files_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
} // namespace react
} // namespace facebook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace facebook {
namespace react {

std::shared_ptr<TurboModule> RNTesterAppModuleProvider(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params) {
auto module = rntester_ModuleProvider(moduleName, params);
if (module != nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace facebook {
namespace react {

std::shared_ptr<TurboModule> RNTesterAppModuleProvider(
const std::string moduleName,
const std::string &moduleName,
const JavaTurboModule::InitParams &params);

} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ void RNTesterTurboModuleManagerDelegate::registerNatives() {
}

std::shared_ptr<TurboModule> RNTesterTurboModuleManagerDelegate::getTurboModule(
const std::string name,
const std::shared_ptr<CallInvoker> jsInvoker) {
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) {
// Not implemented yet: provide pure-C++ NativeModules here.
return nullptr;
}

std::shared_ptr<TurboModule> RNTesterTurboModuleManagerDelegate::getTurboModule(
const std::string name,
const std::string &name,
const JavaTurboModule::InitParams &params) {
return RNTesterAppModuleProvider(name, params);
}

bool RNTesterTurboModuleManagerDelegate::canCreateTurboModule(
std::string name) {
const std::string &name) {
return getTurboModule(name, nullptr) != nullptr ||
getTurboModule(name, {.moduleName = name}) != nullptr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ class RNTesterTurboModuleManagerDelegate
static void registerNatives();

std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::shared_ptr<CallInvoker> jsInvoker) override;
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) override;
std::shared_ptr<TurboModule> getTurboModule(
const std::string name,
const std::string &name,
const JavaTurboModule::InitParams &params) override;

/**
* Test-only method. Allows user to verify whether a TurboModule can be
* created by instances of this class.
*/
bool canCreateTurboModule(std::string name);
bool canCreateTurboModule(const std::string &name);

private:
friend HybridBase;
Expand Down

0 comments on commit 3337add

Please sign in to comment.