diff --git a/ReactCommon/cxxreact/RAMBundleRegistry.cpp b/ReactCommon/cxxreact/RAMBundleRegistry.cpp index 127e06e01..cc61ea254 100644 --- a/ReactCommon/cxxreact/RAMBundleRegistry.cpp +++ b/ReactCommon/cxxreact/RAMBundleRegistry.cpp @@ -12,33 +12,46 @@ namespace react { constexpr uint32_t RAMBundleRegistry::MAIN_BUNDLE_ID; -std::unique_ptr RAMBundleRegistry::singleBundleRegistry(std::unique_ptr mainBundle) { - RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle)); - return std::unique_ptr(registry); +std::unique_ptr RAMBundleRegistry::singleBundleRegistry( + std::unique_ptr mainBundle) { + return folly::make_unique(std::move(mainBundle)); } -std::unique_ptr RAMBundleRegistry::multipleBundlesRegistry(std::unique_ptr mainBundle, std::function(std::string)> factory) { - RAMBundleRegistry *registry = new RAMBundleRegistry(std::move(mainBundle), std::move(factory)); - return std::unique_ptr(registry); +std::unique_ptr RAMBundleRegistry::multipleBundlesRegistry( + std::unique_ptr mainBundle, + std::function(std::string)> factory) { + return folly::make_unique( + std::move(mainBundle), std::move(factory)); } -RAMBundleRegistry::RAMBundleRegistry(std::unique_ptr mainBundle, std::function(std::string)> factory): m_factory(factory) { +RAMBundleRegistry::RAMBundleRegistry( + std::unique_ptr mainBundle, + std::function(std::string)> factory): + m_factory(std::move(factory)) { m_bundles.emplace(MAIN_BUNDLE_ID, std::move(mainBundle)); } -void RAMBundleRegistry::registerBundle(uint32_t bundleId, std::string bundlePath) { - m_bundlePaths.emplace(bundleId, bundlePath); +void RAMBundleRegistry::registerBundle( + uint32_t bundleId, std::string bundlePath) { + m_bundlePaths.emplace(bundleId, std::move(bundlePath)); } -JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32_t moduleId) { +JSModulesUnbundle::Module RAMBundleRegistry::getModule( + uint32_t bundleId, uint32_t moduleId) { if (m_bundles.find(bundleId) == m_bundles.end()) { if (!m_factory) { - throw std::runtime_error("You need to register factory function in order to support multiple RAM bundles."); + throw std::runtime_error( + "You need to register factory function in order to " + "support multiple RAM bundles." + ); } auto bundlePath = m_bundlePaths.find(bundleId); if (bundlePath == m_bundlePaths.end()) { - throw std::runtime_error("In order to fetch RAM bundle from the registry, its file path needs to be registered first."); + throw std::runtime_error( + "In order to fetch RAM bundle from the registry, its file " + "path needs to be registered first." + ); } m_bundles.emplace(bundleId, m_factory(bundlePath->second)); } @@ -53,7 +66,7 @@ JSModulesUnbundle::Module RAMBundleRegistry::getModule(uint32_t bundleId, uint32 }; } -JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const { +JSModulesUnbundle* RAMBundleRegistry::getBundle(uint32_t bundleId) const { return m_bundles.at(bundleId).get(); } diff --git a/ReactCommon/cxxreact/RAMBundleRegistry.h b/ReactCommon/cxxreact/RAMBundleRegistry.h index 2d628f22c..9fb546066 100644 --- a/ReactCommon/cxxreact/RAMBundleRegistry.h +++ b/ReactCommon/cxxreact/RAMBundleRegistry.h @@ -20,26 +20,31 @@ namespace react { class RN_EXPORT RAMBundleRegistry : noncopyable { public: - using unique_ram_bundle = std::unique_ptr; - using bundle_path = std::string; constexpr static uint32_t MAIN_BUNDLE_ID = 0; - static std::unique_ptr singleBundleRegistry(unique_ram_bundle mainBundle); - static std::unique_ptr multipleBundlesRegistry(unique_ram_bundle mainBundle, std::function factory); + static std::unique_ptr singleBundleRegistry( + std::unique_ptr mainBundle); + static std::unique_ptr multipleBundlesRegistry( + std::unique_ptr mainBundle, + std::function(std::string)> factory); + + explicit RAMBundleRegistry( + std::unique_ptr mainBundle, + std::function< + std::unique_ptr(std::string)> factory = nullptr); RAMBundleRegistry(RAMBundleRegistry&&) = default; RAMBundleRegistry& operator=(RAMBundleRegistry&&) = default; - void registerBundle(uint32_t bundleId, bundle_path bundlePath); + void registerBundle(uint32_t bundleId, std::string bundlePath); JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId); virtual ~RAMBundleRegistry() {}; private: - explicit RAMBundleRegistry(unique_ram_bundle mainBundle, std::function factory = {}); - JSModulesUnbundle *getBundle(uint32_t bundleId) const; + JSModulesUnbundle* getBundle(uint32_t bundleId) const; - std::function m_factory; - std::unordered_map m_bundlePaths; - std::unordered_map m_bundles; + std::function(std::string)> m_factory; + std::unordered_map m_bundlePaths; + std::unordered_map> m_bundles; }; } // namespace react