From f8b683b3ee5ef4b2b84968db9c3023c59bf99220 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Mon, 15 May 2017 09:12:24 -0700 Subject: [PATCH] Copy-free Source loading implementation Reviewed By: amnn Differential Revision: D4914165 fbshipit-source-id: 38851679cb696c41f59edfd0d2005faf37813b23 --- ReactCommon/cxxreact/JSCExecutor.cpp | 21 +++++++++++++++++++-- ReactCommon/cxxreact/JSCExecutor.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 2aaf9d8e8a9..681914fa0b6 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -357,9 +357,12 @@ void JSCExecutor::loadApplicationScript(std::unique_ptr scrip { SystraceSection s_("JSCExecutor::loadApplicationScript-createExpectingAscii"); ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_START); - jsScript = jsStringFromBigString(m_context, *script); + jsScript = adoptString(std::move(script)); ReactMarker::logMarker(ReactMarker::JS_BUNDLE_STRING_CONVERT_STOP); } + #ifdef WITH_FBSYSTRACE + fbsystrace_end_section(TRACE_TAG_REACT_CXX_BRIDGE); + #endif SystraceSection s_("JSCExecutor::loadApplicationScript-evaluateScript"); evaluateScript(m_context, jsScript, jsSourceURL); @@ -521,13 +524,27 @@ void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr script) { +#if defined(WITH_FBJSCEXTENSIONS) + const JSBigString* string = script.release(); + auto jsString = JSStringCreateAdoptingExternal(string->c_str(), string->size(), (void*)string, [](void* s) { + delete static_cast(s); + }); + return String::adopt(m_context, jsString); +#else + return script->isAscii() + ? String::createExpectingAscii(m_context, script->c_str(), script->size()) + : String(m_context, script->c_str()); +#endif +} + void* JSCExecutor::getJavaScriptContext() { return m_context; } diff --git a/ReactCommon/cxxreact/JSCExecutor.h b/ReactCommon/cxxreact/JSCExecutor.h index bf5560c90bb..473cca7c754 100644 --- a/ReactCommon/cxxreact/JSCExecutor.h +++ b/ReactCommon/cxxreact/JSCExecutor.h @@ -113,6 +113,8 @@ private: void flushQueueImmediate(Value&&); void loadModule(uint32_t moduleId); + String adoptString(std::unique_ptr); + template void installNativeHook(const char* name); JSValueRef getNativeModule(JSObjectRef object, JSStringRef propertyName);