mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Replace folly::make_unique with std::make_unique (#26730)
Summary: There is a mixed usage of `folly::make_unique` and `std::make_unique`. Soon, `folly::make_unique` may be removed (see [this PR](https://github.com/facebook/folly/pull/1150)). Since `react-native` only supports C++14-compilers and later, switch to always using `std::make_unique`. ## Changelog [Internal] [Removed] - Replace folly::make_unique with std::make_unique Pull Request resolved: https://github.com/facebook/react-native/pull/26730 Test Plan: Running the existing test suite. No change in behavior is expected. Joshua Gross: buck install -r fb4a, make sure MP Home and forced teardown works okay on android Reviewed By: shergin Differential Revision: D18062400 Pulled By: JoshuaGross fbshipit-source-id: 978ca794c7e972db872a8dcc57c31bdec7451481
This commit is contained in:
committed by
Facebook Github Bot
parent
468d1a2d2e
commit
ba18ee9b87
@@ -9,37 +9,39 @@
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <folly/Memory.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)> JSIndexedRAMBundle::buildFactory() {
|
||||
return [](const std::string& bundlePath){
|
||||
return folly::make_unique<JSIndexedRAMBundle>(bundlePath.c_str());
|
||||
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)>
|
||||
JSIndexedRAMBundle::buildFactory() {
|
||||
return [](const std::string &bundlePath) {
|
||||
return std::make_unique<JSIndexedRAMBundle>(bundlePath.c_str());
|
||||
};
|
||||
}
|
||||
|
||||
JSIndexedRAMBundle::JSIndexedRAMBundle(const char *sourcePath) {
|
||||
m_bundle = std::make_unique<std::ifstream>(sourcePath, std::ifstream::binary);
|
||||
if (!m_bundle) {
|
||||
throw std::ios_base::failure(
|
||||
folly::to<std::string>("Bundle ", sourcePath,
|
||||
"cannot be opened: ", m_bundle->rdstate()));
|
||||
throw std::ios_base::failure(folly::to<std::string>(
|
||||
"Bundle ", sourcePath, "cannot be opened: ", m_bundle->rdstate()));
|
||||
}
|
||||
init();
|
||||
}
|
||||
|
||||
JSIndexedRAMBundle::JSIndexedRAMBundle(std::unique_ptr<const JSBigString> script) {
|
||||
JSIndexedRAMBundle::JSIndexedRAMBundle(
|
||||
std::unique_ptr<const JSBigString> script) {
|
||||
// tmpStream is needed because m_bundle is std::istream type
|
||||
// which has no member 'write'
|
||||
std::unique_ptr<std::stringstream> tmpStream = std::make_unique<std::stringstream>();
|
||||
std::unique_ptr<std::stringstream> tmpStream =
|
||||
std::make_unique<std::stringstream>();
|
||||
tmpStream->write(script->c_str(), script->size());
|
||||
m_bundle = std::move(tmpStream);
|
||||
if (!m_bundle) {
|
||||
throw std::ios_base::failure(
|
||||
folly::to<std::string>("Bundle from string cannot be opened: ", m_bundle->rdstate()));
|
||||
throw std::ios_base::failure(folly::to<std::string>(
|
||||
"Bundle from string cannot be opened: ", m_bundle->rdstate()));
|
||||
}
|
||||
init();
|
||||
}
|
||||
@@ -48,8 +50,8 @@ void JSIndexedRAMBundle::init() {
|
||||
// read in magic header, number of entries, and length of the startup section
|
||||
uint32_t header[3];
|
||||
static_assert(
|
||||
sizeof(header) == 12,
|
||||
"header size must exactly match the input file format");
|
||||
sizeof(header) == 12,
|
||||
"header size must exactly match the input file format");
|
||||
|
||||
readBundle(reinterpret_cast<char *>(header), sizeof(header));
|
||||
const size_t numTableEntries = folly::Endian::little(header[1]);
|
||||
@@ -61,15 +63,17 @@ void JSIndexedRAMBundle::init() {
|
||||
|
||||
// read the lookup table from the file
|
||||
readBundle(
|
||||
reinterpret_cast<char *>(m_table.data.get()), m_table.byteLength());
|
||||
reinterpret_cast<char *>(m_table.data.get()), m_table.byteLength());
|
||||
|
||||
// read the startup code
|
||||
m_startupCode = std::unique_ptr<JSBigBufferString>(new JSBigBufferString{startupCodeSize - 1});
|
||||
m_startupCode = std::unique_ptr<JSBigBufferString>(
|
||||
new JSBigBufferString{startupCodeSize - 1});
|
||||
|
||||
readBundle(m_startupCode->data(), startupCodeSize - 1);
|
||||
}
|
||||
|
||||
JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(uint32_t moduleId) const {
|
||||
JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(
|
||||
uint32_t moduleId) const {
|
||||
Module ret;
|
||||
ret.name = folly::to<std::string>(moduleId, ".js");
|
||||
ret.code = getModuleCode(moduleId);
|
||||
@@ -77,7 +81,8 @@ JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(uint32_t moduleId) cons
|
||||
}
|
||||
|
||||
std::unique_ptr<const JSBigString> JSIndexedRAMBundle::getStartupCode() {
|
||||
CHECK(m_startupCode) << "startup code for a RAM Bundle can only be retrieved once";
|
||||
CHECK(m_startupCode)
|
||||
<< "startup code for a RAM Bundle can only be retrieved once";
|
||||
return std::move(m_startupCode);
|
||||
}
|
||||
|
||||
@@ -85,24 +90,29 @@ std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const {
|
||||
const auto moduleData = id < m_table.numEntries ? &m_table.data[id] : nullptr;
|
||||
|
||||
// entries without associated code have offset = 0 and length = 0
|
||||
const uint32_t length = moduleData ? folly::Endian::little(moduleData->length) : 0;
|
||||
const uint32_t length =
|
||||
moduleData ? folly::Endian::little(moduleData->length) : 0;
|
||||
if (length == 0) {
|
||||
throw std::ios_base::failure(
|
||||
folly::to<std::string>("Error loading module", id, "from RAM Bundle"));
|
||||
folly::to<std::string>("Error loading module", id, "from RAM Bundle"));
|
||||
}
|
||||
|
||||
std::string ret(length - 1, '\0');
|
||||
readBundle(&ret.front(), length - 1, m_baseOffset + folly::Endian::little(moduleData->offset));
|
||||
readBundle(
|
||||
&ret.front(),
|
||||
length - 1,
|
||||
m_baseOffset + folly::Endian::little(moduleData->offset));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void JSIndexedRAMBundle::readBundle(char *buffer, const std::streamsize bytes) const {
|
||||
void JSIndexedRAMBundle::readBundle(char *buffer, const std::streamsize bytes)
|
||||
const {
|
||||
if (!m_bundle->read(buffer, bytes)) {
|
||||
if (m_bundle->rdstate() & std::ios::eofbit) {
|
||||
throw std::ios_base::failure("Unexpected end of RAM Bundle file");
|
||||
}
|
||||
throw std::ios_base::failure(
|
||||
folly::to<std::string>("Error reading RAM Bundle: ", m_bundle->rdstate()));
|
||||
throw std::ios_base::failure(folly::to<std::string>(
|
||||
"Error reading RAM Bundle: ", m_bundle->rdstate()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,13 +120,12 @@ void JSIndexedRAMBundle::readBundle(
|
||||
char *buffer,
|
||||
const std::streamsize bytes,
|
||||
const std::ifstream::pos_type position) const {
|
||||
|
||||
if (!m_bundle->seekg(position)) {
|
||||
throw std::ios_base::failure(
|
||||
folly::to<std::string>("Error reading RAM Bundle: ", m_bundle->rdstate()));
|
||||
throw std::ios_base::failure(folly::to<std::string>(
|
||||
"Error reading RAM Bundle: ", m_bundle->rdstate()));
|
||||
}
|
||||
readBundle(buffer, bytes);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
Reference in New Issue
Block a user