Skip to content

Commit 16fea5d

Browse files
committed
Use emplace instead of indexing into _nodeAddons
1 parent 9d21228 commit 16fea5d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/react-native-node-api-modules/cpp/CxxNodeApiHostModule.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ jsi::Value CxxNodeApiHostModule::requireNodeAddon(jsi::Runtime &rt,
2626
const jsi::String path) {
2727
const std::string pathStr = path.utf8(rt);
2828

29+
auto [it, inserted] = nodeAddons_.emplace(pathStr);
30+
NodeAddon &addon = it->second;
31+
2932
// Check if this module has been loaded already, if not then load it...
30-
if (nodeAddons_.end() == nodeAddons_.find(pathStr)) {
31-
NodeAddon &addon = nodeAddons_[pathStr];
33+
if (inserted) {
3234
if (!loadNodeAddon(addon, pathStr)) {
3335
return jsi::Value::undefined();
3436
}
3537
}
3638

37-
// Library has been loaded, make sure that the "exports" was populated.
38-
// If not, then just call the "napi_register_module_v1" function...
39-
NodeAddon &addon = nodeAddons_[pathStr];
40-
4139
// Initialize the addon if it has not already been initialized
4240
if (!rt.global().hasProperty(rt, addon.generatedName.data())) {
4341
initializeNodeModule(rt, addon);
@@ -105,4 +103,4 @@ bool CxxNodeApiHostModule::initializeNodeModule(jsi::Runtime &rt,
105103
return true;
106104
}
107105

108-
} // namespace callstack::nodeapihost
106+
} // namespace callstack::nodeapihost

0 commit comments

Comments
 (0)