Rename JSBigMmapString -> JSBigOptimizedBundleString
Summary: `JSBigMmapString` needs to know too much about the details of the "optimized bundle" format. In honour of this fact, I'm renaming it to `JSBigOptimizedBundleString`. In a following diff, I will introduce a new class just for File-backed Strings, whose only responsibility is dealing with an mmaped region. This diff already pulls in some fixes for formatting reference and pointer declarations from the linter. Reviewed By: michalgr Differential Revision: D4189391 fbshipit-source-id: b376c2a8d9ae5b83575da8457e607bbbfc648ebd
This commit is contained in:
parent
89d81b34db
commit
79fa6d41a1
|
@ -18,26 +18,26 @@ void JSExecutor::loadApplicationScript(std::string bundlePath, std::string sourc
|
||||||
throw std::runtime_error("No unpacked js source file");
|
throw std::runtime_error("No unpacked js source file");
|
||||||
}
|
}
|
||||||
return loadApplicationScript(
|
return loadApplicationScript(
|
||||||
JSBigMmapString::fromOptimizedBundle(bundlePath),
|
JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath),
|
||||||
std::move(sourceURL));
|
std::move(sourceURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSBigMmapString::Encoding encodingFromByte(uint8_t byte) {
|
static JSBigOptimizedBundleString::Encoding encodingFromByte(uint8_t byte) {
|
||||||
switch (byte) {
|
switch (byte) {
|
||||||
case 0:
|
case 0:
|
||||||
return JSBigMmapString::Encoding::Unknown;
|
return JSBigOptimizedBundleString::Encoding::Unknown;
|
||||||
case 1:
|
case 1:
|
||||||
return JSBigMmapString::Encoding::Ascii;
|
return JSBigOptimizedBundleString::Encoding::Ascii;
|
||||||
case 2:
|
case 2:
|
||||||
return JSBigMmapString::Encoding::Utf8;
|
return JSBigOptimizedBundleString::Encoding::Utf8;
|
||||||
case 3:
|
case 3:
|
||||||
return JSBigMmapString::Encoding::Utf16;
|
return JSBigOptimizedBundleString::Encoding::Utf16;
|
||||||
default:
|
default:
|
||||||
throw std::invalid_argument("Unknown bundle encoding");
|
throw std::invalid_argument("Unknown bundle encoding");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<const JSBigMmapString> JSBigMmapString::fromOptimizedBundle(
|
std::unique_ptr<const JSBigOptimizedBundleString> JSBigOptimizedBundleString::fromOptimizedBundle(
|
||||||
const std::string& bundlePath) {
|
const std::string& bundlePath) {
|
||||||
uint8_t sha1[20];
|
uint8_t sha1[20];
|
||||||
uint8_t encoding;
|
uint8_t encoding;
|
||||||
|
@ -62,7 +62,7 @@ std::unique_ptr<const JSBigMmapString> JSBigMmapString::fromOptimizedBundle(
|
||||||
|
|
||||||
folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on js bundle failed.");
|
folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on js bundle failed.");
|
||||||
|
|
||||||
return folly::make_unique<const JSBigMmapString>(
|
return folly::make_unique<const JSBigOptimizedBundleString>(
|
||||||
fd,
|
fd,
|
||||||
fileInfo.st_size,
|
fileInfo.st_size,
|
||||||
sha1,
|
sha1,
|
||||||
|
|
|
@ -148,7 +148,7 @@ private:
|
||||||
size_t m_size;
|
size_t m_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class JSBigMmapString : public JSBigString {
|
class JSBigOptimizedBundleString : public JSBigString {
|
||||||
public:
|
public:
|
||||||
enum class Encoding {
|
enum class Encoding {
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -158,7 +158,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
JSBigMmapString(int fd, size_t size, const uint8_t sha1[20], Encoding encoding) :
|
JSBigOptimizedBundleString(int fd, size_t size, const uint8_t sha1[20], Encoding encoding) :
|
||||||
m_fd(fd),
|
m_fd(fd),
|
||||||
m_size(size),
|
m_size(size),
|
||||||
m_encoding(encoding),
|
m_encoding(encoding),
|
||||||
|
@ -167,7 +167,7 @@ public:
|
||||||
memcpy(m_hash, sha1, 20);
|
memcpy(m_hash, sha1, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
~JSBigMmapString() {
|
~JSBigOptimizedBundleString() {
|
||||||
if (m_str) {
|
if (m_str) {
|
||||||
CHECK(munmap((void *)m_str, m_size) != -1);
|
CHECK(munmap((void *)m_str, m_size) != -1);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ public:
|
||||||
return m_encoding;
|
return m_encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<const JSBigMmapString> fromOptimizedBundle(const std::string& bundlePath);
|
static std::unique_ptr<const JSBigOptimizedBundleString> fromOptimizedBundle(const std::string& bundlePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_fd;
|
int m_fd;
|
||||||
|
@ -264,6 +264,4 @@ public:
|
||||||
virtual ~JSExecutor() {}
|
virtual ~JSExecutor() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<const JSBigMmapString> readJSBundle(const std::string& path);
|
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -334,8 +334,8 @@ void JSCExecutor::loadApplicationScript(
|
||||||
"Could not create compiled source code"
|
"Could not create compiled source code"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
auto jsScriptBigString = JSBigMmapString::fromOptimizedBundle(bundlePath);
|
auto jsScriptBigString = JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath);
|
||||||
if (jsScriptBigString->encoding() != JSBigMmapString::Encoding::Ascii) {
|
if (!jsScriptBigString->isAscii()) {
|
||||||
LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path";
|
LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path";
|
||||||
return loadApplicationScript(std::move(jsScriptBigString), sourceURL);
|
return loadApplicationScript(std::move(jsScriptBigString), sourceURL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue