From be0abd17e5c37bd7dcc1728c41d5bcfb64f3a4b2 Mon Sep 17 00:00:00 2001 From: Alexander Blom Date: Thu, 7 Jul 2016 08:44:01 -0700 Subject: [PATCH] Remove a bunch of copies Reviewed By: astreet Differential Revision: D3475592 fbshipit-source-id: 37148bb8d8d47e9301ad549b183029337f7c4ca0 --- .../jni/xreact/jni/CatalystInstanceImpl.cpp | 4 ++-- ReactCommon/cxxreact/Instance.cpp | 4 ++-- ReactCommon/cxxreact/Instance.h | 2 +- ReactCommon/cxxreact/NativeToJsBridge.cpp | 17 ++++++++--------- ReactCommon/cxxreact/NativeToJsBridge.h | 8 ++++---- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp index 3ac86d9e2..612107b7c 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp @@ -297,8 +297,8 @@ void CatalystInstanceImpl::callJSFunction( // strings otherwise. Eventually, we'll probably want to modify the stack // from the JS proxy through here to use strings, too. instance_->callJSFunction(token->getExecutorToken(nullptr), - module, - method, + std::move(module), + std::move(method), std::move(arguments->array)); } diff --git a/ReactCommon/cxxreact/Instance.cpp b/ReactCommon/cxxreact/Instance.cpp index 2168bad0d..cbc8e656b 100644 --- a/ReactCommon/cxxreact/Instance.cpp +++ b/ReactCommon/cxxreact/Instance.cpp @@ -101,10 +101,10 @@ void Instance::setGlobalVariable(std::string propName, nativeToJsBridge_->setGlobalVariable(std::move(propName), std::move(jsonValue)); } -void Instance::callJSFunction(ExecutorToken token, const std::string& module, const std::string& method, +void Instance::callJSFunction(ExecutorToken token, std::string&& module, std::string&& method, folly::dynamic&& params) { callback_->incrementPendingJSCalls(); - nativeToJsBridge_->callFunction(token, module, method, std::move(params)); + nativeToJsBridge_->callFunction(token, std::move(module), std::move(method), std::move(params)); } void Instance::callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params) { diff --git a/ReactCommon/cxxreact/Instance.h b/ReactCommon/cxxreact/Instance.h index af2f1bda9..fada0a7cf 100644 --- a/ReactCommon/cxxreact/Instance.h +++ b/ReactCommon/cxxreact/Instance.h @@ -44,7 +44,7 @@ class Instance { void startProfiler(const std::string& title); void stopProfiler(const std::string& title, const std::string& filename); void setGlobalVariable(std::string propName, std::unique_ptr jsonValue); - void callJSFunction(ExecutorToken token, const std::string& module, const std::string& method, + void callJSFunction(ExecutorToken token, std::string&& module, std::string&& method, folly::dynamic&& params); void callJSCallback(ExecutorToken token, uint64_t callbackId, folly::dynamic&& params); MethodCallResult callSerializableNativeHook(ExecutorToken token, unsigned int moduleId, diff --git a/ReactCommon/cxxreact/NativeToJsBridge.cpp b/ReactCommon/cxxreact/NativeToJsBridge.cpp index 317cc8712..8da6bb0fc 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.cpp +++ b/ReactCommon/cxxreact/NativeToJsBridge.cpp @@ -143,14 +143,14 @@ void NativeToJsBridge::loadApplicationUnbundle( void NativeToJsBridge::callFunction( ExecutorToken executorToken, - const std::string& moduleId, - const std::string& methodId, - const folly::dynamic& arguments) { + std::string&& module, + std::string&& method, + folly::dynamic&& arguments) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; std::string tracingName = fbsystrace_is_tracing(TRACE_TAG_REACT_CXX_BRIDGE) ? - folly::to("JSCall__", moduleId, '_', methodId) : std::string(); + folly::to("JSCall__", module, '_', method) : std::string(); SystraceSection s(tracingName.c_str()); FbSystraceAsyncFlow::begin( TRACE_TAG_REACT_CXX_BRIDGE, @@ -160,7 +160,7 @@ void NativeToJsBridge::callFunction( std::string tracingName; #endif - runOnExecutorQueue(executorToken, [moduleId, methodId, arguments, tracingName = std::move(tracingName), systraceCookie] (JSExecutor* executor) { + runOnExecutorQueue(executorToken, [module = std::move(module), method = std::move(method), arguments = std::move(arguments), tracingName = std::move(tracingName), systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, @@ -172,12 +172,11 @@ void NativeToJsBridge::callFunction( // This is safe because we are running on the executor's thread: it won't // destruct until after it's been unregistered (which we check above) and // that will happen on this thread - executor->callFunction(moduleId, methodId, arguments); + executor->callFunction(module, method, arguments); }); } -void NativeToJsBridge::invokeCallback(ExecutorToken executorToken, const double callbackId, - const folly::dynamic& arguments) { +void NativeToJsBridge::invokeCallback(ExecutorToken executorToken, double callbackId, folly::dynamic&& arguments) { int systraceCookie = -1; #ifdef WITH_FBSYSTRACE systraceCookie = m_systraceCookie++; @@ -187,7 +186,7 @@ void NativeToJsBridge::invokeCallback(ExecutorToken executorToken, const double systraceCookie); #endif - runOnExecutorQueue(executorToken, [callbackId, arguments, systraceCookie] (JSExecutor* executor) { + runOnExecutorQueue(executorToken, [callbackId, arguments = std::move(arguments), systraceCookie] (JSExecutor* executor) { #ifdef WITH_FBSYSTRACE FbSystraceAsyncFlow::end( TRACE_TAG_REACT_CXX_BRIDGE, diff --git a/ReactCommon/cxxreact/NativeToJsBridge.h b/ReactCommon/cxxreact/NativeToJsBridge.h index fea5a86ee..786c26867 100644 --- a/ReactCommon/cxxreact/NativeToJsBridge.h +++ b/ReactCommon/cxxreact/NativeToJsBridge.h @@ -68,14 +68,14 @@ public: */ void callFunction( ExecutorToken executorToken, - const std::string& moduleId, - const std::string& methodId, - const folly::dynamic& args); + std::string&& module, + std::string&& method, + folly::dynamic&& args); /** * Invokes a callback with the cbID, and optional additional arguments in JS. */ - void invokeCallback(ExecutorToken executorToken, const double callbackId, const folly::dynamic& args); + void invokeCallback(ExecutorToken executorToken, double callbackId, folly::dynamic&& args); /** * Starts the JS application from an "bundle", i.e. a JavaScript file that