mirror of
https://github.com/status-im/react-native.git
synced 2025-02-25 23:55:23 +00:00
remove premature optimizations
Reviewed By: javache Differential Revision: D3325805 fbshipit-source-id: cdf8f4f3744d70fd37e8fa35c44ca8110ea4395a
This commit is contained in:
parent
5d06402b4a
commit
4c76e5476c
@ -47,14 +47,13 @@ struct __attribute__((packed)) ModuleData {
|
|||||||
|
|
||||||
using file_ptr = std::unique_ptr<FILE, decltype(&fclose)>;
|
using file_ptr = std::unique_ptr<FILE, decltype(&fclose)>;
|
||||||
using memory_ptr = std::unique_ptr<void, decltype(&free)>;
|
using memory_ptr = std::unique_ptr<void, decltype(&free)>;
|
||||||
using table_ptr = std::unique_ptr<ModuleData[], decltype(&free)>;
|
|
||||||
|
|
||||||
struct RandomAccessBundleData {
|
struct RandomAccessBundleData {
|
||||||
file_ptr bundle;
|
file_ptr bundle;
|
||||||
size_t baseOffset;
|
size_t baseOffset;
|
||||||
size_t numTableEntries;
|
size_t numTableEntries;
|
||||||
table_ptr table;
|
std::unique_ptr<ModuleData[]> table;
|
||||||
RandomAccessBundleData(): bundle(nullptr, fclose), table(nullptr, free) {}
|
RandomAccessBundleData(): bundle(nullptr, fclose) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RandomAccessBundleStartupCode {
|
struct RandomAccessBundleStartupCode {
|
||||||
@ -718,13 +717,13 @@ static bool readRandomAccessModule(const RandomAccessBundleData& bundleData, siz
|
|||||||
|
|
||||||
static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleID, size_t offset, size_t size)
|
static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleID, size_t offset, size_t size)
|
||||||
{
|
{
|
||||||
auto data = std::unique_ptr<char[]>(new char[size]);
|
auto data = std::make_unique<char[]>(size);
|
||||||
if (!readRandomAccessModule(executor->_randomAccessBundle, offset, size, data.get())) {
|
if (!readRandomAccessModule(executor->_randomAccessBundle, offset, size, data.get())) {
|
||||||
RCTFatal(RCTErrorWithMessage(@"Error loading RAM module"));
|
RCTFatal(RCTErrorWithMessage(@"Error loading RAM module"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char url[14]; // 10 = maximum decimal digits in a 32bit unsigned int + ".js" + null byte
|
char url[14]; // 10 = maximum decimal digits in a 32bit unsigned int + ".js" + null byte
|
||||||
sprintf(url, "%" PRIu32 ".js", moduleID);
|
sprintf(url, "%" PRIu32 ".js", moduleID);
|
||||||
|
|
||||||
JSStringRef code = JSStringCreateWithUTF8CString(data.get());
|
JSStringRef code = JSStringCreateWithUTF8CString(data.get());
|
||||||
@ -758,7 +757,7 @@ static void executeRandomAccessModule(RCTJSCExecutor *executor, uint32_t moduleI
|
|||||||
|
|
||||||
RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresCount, 1);
|
RCTPerformanceLoggerAdd(RCTPLRAMNativeRequiresCount, 1);
|
||||||
RCTPerformanceLoggerAppendStart(RCTPLRAMNativeRequires);
|
RCTPerformanceLoggerAppendStart(RCTPLRAMNativeRequires);
|
||||||
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
|
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways,
|
||||||
[@"nativeRequire_" stringByAppendingFormat:@"%@", moduleID], nil);
|
[@"nativeRequire_" stringByAppendingFormat:@"%@", moduleID], nil);
|
||||||
|
|
||||||
const uint32_t ID = [moduleID unsignedIntValue];
|
const uint32_t ID = [moduleID unsignedIntValue];
|
||||||
@ -794,7 +793,7 @@ static RandomAccessBundleStartupCode readRAMBundle(file_ptr bundle, RandomAccess
|
|||||||
const size_t tableSize = numTableEntries * sizeof(ModuleData);
|
const size_t tableSize = numTableEntries * sizeof(ModuleData);
|
||||||
|
|
||||||
// allocate memory for meta data and lookup table. malloc instead of new to avoid constructor calls
|
// allocate memory for meta data and lookup table. malloc instead of new to avoid constructor calls
|
||||||
table_ptr table(static_cast<ModuleData *>(malloc(tableSize)), free);
|
auto table = std::make_unique<ModuleData[]>(numTableEntries);
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return RandomAccessBundleStartupCode::empty();
|
return RandomAccessBundleStartupCode::empty();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user