From 79fa6d41a155e8e5bb0c5a71c65baaedd806b4f7 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Wed, 16 Nov 2016 15:08:41 -0800 Subject: [PATCH] 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 --- ReactCommon/cxxreact/Executor.cpp | 16 ++++++++-------- ReactCommon/cxxreact/Executor.h | 10 ++++------ ReactCommon/cxxreact/JSCExecutor.cpp | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/ReactCommon/cxxreact/Executor.cpp b/ReactCommon/cxxreact/Executor.cpp index 7e00ff164..54ae86f0d 100644 --- a/ReactCommon/cxxreact/Executor.cpp +++ b/ReactCommon/cxxreact/Executor.cpp @@ -18,26 +18,26 @@ void JSExecutor::loadApplicationScript(std::string bundlePath, std::string sourc throw std::runtime_error("No unpacked js source file"); } return loadApplicationScript( - JSBigMmapString::fromOptimizedBundle(bundlePath), + JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath), std::move(sourceURL)); } -static JSBigMmapString::Encoding encodingFromByte(uint8_t byte) { +static JSBigOptimizedBundleString::Encoding encodingFromByte(uint8_t byte) { switch (byte) { case 0: - return JSBigMmapString::Encoding::Unknown; + return JSBigOptimizedBundleString::Encoding::Unknown; case 1: - return JSBigMmapString::Encoding::Ascii; + return JSBigOptimizedBundleString::Encoding::Ascii; case 2: - return JSBigMmapString::Encoding::Utf8; + return JSBigOptimizedBundleString::Encoding::Utf8; case 3: - return JSBigMmapString::Encoding::Utf16; + return JSBigOptimizedBundleString::Encoding::Utf16; default: throw std::invalid_argument("Unknown bundle encoding"); } } -std::unique_ptr JSBigMmapString::fromOptimizedBundle( +std::unique_ptr JSBigOptimizedBundleString::fromOptimizedBundle( const std::string& bundlePath) { uint8_t sha1[20]; uint8_t encoding; @@ -62,7 +62,7 @@ std::unique_ptr JSBigMmapString::fromOptimizedBundle( folly::checkUnixError(::fstat(fd, &fileInfo), "fstat on js bundle failed."); - return folly::make_unique( + return folly::make_unique( fd, fileInfo.st_size, sha1, diff --git a/ReactCommon/cxxreact/Executor.h b/ReactCommon/cxxreact/Executor.h index 8d620ad66..3f2b103a4 100644 --- a/ReactCommon/cxxreact/Executor.h +++ b/ReactCommon/cxxreact/Executor.h @@ -148,7 +148,7 @@ private: size_t m_size; }; -class JSBigMmapString : public JSBigString { +class JSBigOptimizedBundleString : public JSBigString { public: enum class Encoding { 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_size(size), m_encoding(encoding), @@ -167,7 +167,7 @@ public: memcpy(m_hash, sha1, 20); } - ~JSBigMmapString() { + ~JSBigOptimizedBundleString() { if (m_str) { CHECK(munmap((void *)m_str, m_size) != -1); } @@ -202,7 +202,7 @@ public: return m_encoding; } - static std::unique_ptr fromOptimizedBundle(const std::string& bundlePath); + static std::unique_ptr fromOptimizedBundle(const std::string& bundlePath); private: int m_fd; @@ -264,6 +264,4 @@ public: virtual ~JSExecutor() {} }; -std::unique_ptr readJSBundle(const std::string& path); - } } diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 8145f2b6b..1f9b3bee8 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -334,8 +334,8 @@ void JSCExecutor::loadApplicationScript( "Could not create compiled source code" ); } else { - auto jsScriptBigString = JSBigMmapString::fromOptimizedBundle(bundlePath); - if (jsScriptBigString->encoding() != JSBigMmapString::Encoding::Ascii) { + auto jsScriptBigString = JSBigOptimizedBundleString::fromOptimizedBundle(bundlePath); + if (!jsScriptBigString->isAscii()) { LOG(WARNING) << "Bundle is not ASCII encoded - falling back to the slow path"; return loadApplicationScript(std::move(jsScriptBigString), sourceURL); }