Introduce non-copyable JSBigString for managing large strings efficiently

Reviewed By: astreet

Differential Revision: D3234836

fbshipit-source-id: 2b95b585dc1215988b88cf0d609c778a95b362a1
This commit is contained in:
Marc Horowitz
2016-05-13 17:29:00 -07:00
committed by Facebook Github Bot 8
parent f433ed716c
commit 9e9dfd2ac9
12 changed files with 180 additions and 72 deletions
+18 -10
View File
@@ -37,22 +37,26 @@ Bridge::~Bridge() {
CHECK(*m_destroyed) << "Bridge::destroy() must be called before deallocating the Bridge!";
}
void Bridge::loadApplicationScript(const std::string& script, const std::string& sourceURL) {
void Bridge::loadApplicationScript(std::unique_ptr<const JSBigString> script,
std::string sourceURL) {
// TODO(t11144533): Add assert that we are on the correct thread
m_mainExecutor->loadApplicationScript(script, sourceURL);
m_mainExecutor->loadApplicationScript(std::move(script), std::move(sourceURL));
}
void Bridge::loadApplicationUnbundle(
std::unique_ptr<JSModulesUnbundle> unbundle,
const std::string& startupScript,
const std::string& startupScriptSourceURL) {
std::unique_ptr<const JSBigString> startupScript,
std::string startupScriptSourceURL) {
runOnExecutorQueue(
*m_mainExecutorToken,
[unbundle=folly::makeMoveWrapper(std::move(unbundle)), startupScript, startupScriptSourceURL]
[unbundle=folly::makeMoveWrapper(std::move(unbundle)),
startupScript=folly::makeMoveWrapper(std::move(startupScript)),
startupScriptSourceURL=std::move(startupScriptSourceURL)]
(JSExecutor* executor) mutable {
executor->setJSModulesUnbundle(unbundle.move());
executor->loadApplicationScript(startupScript, startupScriptSourceURL);
executor->loadApplicationScript(std::move(*startupScript),
std::move(startupScriptSourceURL));
});
}
@@ -108,10 +112,14 @@ void Bridge::invokeCallback(ExecutorToken executorToken, const double callbackId
});
}
void Bridge::setGlobalVariable(const std::string& propName, const std::string& jsonValue) {
runOnExecutorQueue(*m_mainExecutorToken, [=] (JSExecutor* executor) {
executor->setGlobalVariable(propName, jsonValue);
});
void Bridge::setGlobalVariable(std::string propName,
std::unique_ptr<const JSBigString> jsonValue) {
runOnExecutorQueue(
*m_mainExecutorToken,
[propName=std::move(propName), jsonValue=folly::makeMoveWrapper(std::move(jsonValue))]
(JSExecutor* executor) mutable {
executor->setGlobalVariable(propName, jsonValue.move());
});
}
void* Bridge::getJavaScriptContext() {