mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support experimental re-mmap wrappers
Summary: Add experimental support for reordering the pages of a file that is mmap:ed by JSBigFileString. The wrapper is auto-detected (by checking file size and magic header) and transparently reorders the pages. Reviewed By: ridiculousfish Differential Revision: D14721397 fbshipit-source-id: 34e095350a9eeb9b07105bed6f3379f2fe472ae6
This commit is contained in:
committed by
Facebook Github Bot
parent
7944d47a63
commit
407dca8cf0
@@ -60,3 +60,46 @@ TEST(JSBigFileString, MapPartTest) {
|
||||
ASSERT_EQ(needle[i], bigStr.c_str()[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(JSBigFileString, RemapTest) {
|
||||
static const uint8_t kRemapMagic[] = {
|
||||
0xc6, 0x1f, 0xbc, 0x03, 0xc1, 0x03, 0x19, 0x1f, 0xa1, 0xd0, 0xeb, 0x73
|
||||
};
|
||||
std::string data(std::begin(kRemapMagic), std::end(kRemapMagic));
|
||||
auto app = [&data](uint16_t v) {
|
||||
data.append(reinterpret_cast<char *>(&v), sizeof(v));
|
||||
};
|
||||
size_t pageSizeLog2 = 16;
|
||||
app(pageSizeLog2);
|
||||
size_t pageSize = 1 << pageSizeLog2;
|
||||
app(1); // header pages
|
||||
app(2); // num mappings
|
||||
// file page 0 -> memory page 1
|
||||
app(1); // memory page
|
||||
app(1); // num pages
|
||||
// file page 1 -> memory page 0
|
||||
app(0); // memory page
|
||||
app(1); // num pages
|
||||
while (data.size() < pageSize) {
|
||||
app(0);
|
||||
}
|
||||
while (data.size() < pageSize * 2) {
|
||||
app(0x1111);
|
||||
}
|
||||
while (data.size() < pageSize * 3) {
|
||||
app(0x2222);
|
||||
}
|
||||
|
||||
int fd = tempFileFromString(data);
|
||||
JSBigFileString bigStr {fd, data.size()};
|
||||
|
||||
ASSERT_EQ(pageSize * 2, bigStr.size());
|
||||
auto remapped = bigStr.c_str();
|
||||
size_t i = 0;
|
||||
for (; i < pageSize; ++i) {
|
||||
ASSERT_EQ(0x22, remapped[i]);
|
||||
}
|
||||
for (; i < pageSize * 2; ++i) {
|
||||
ASSERT_EQ(0x11, remapped[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user