From 15ba4a4f882ee5fd8fb4f8822ed3c97890e695a6 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 22 Aug 2023 03:29:49 -0700 Subject: [PATCH] Optimize arg conversion in SurfaceRegistryBinding (#39094) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39094 We can construct the outer jsi::Object directly instead of going through `valueFromDynamic` for the whole thing. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D48519751 fbshipit-source-id: 0287c22d0c966612b9af4c40b460e07fed2f1f2b --- .../uimanager/SurfaceRegistryBinding.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp index 91125c1f9a595d..5a1739f8d1fe36 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/SurfaceRegistryBinding.cpp @@ -36,10 +36,11 @@ void SurfaceRegistryBinding::startSurface( folly::dynamic const &initialProps, DisplayMode displayMode) { SystraceSection s("SurfaceRegistryBinding::startSurface"); - folly::dynamic parameters = folly::dynamic::object(); - parameters["rootTag"] = surfaceId; - parameters["initialProps"] = initialProps; - parameters["fabric"] = true; + jsi::Object parameters(runtime); + parameters.setProperty(runtime, "rootTag", surfaceId); + parameters.setProperty( + runtime, "initialProps", jsi::valueFromDynamic(runtime, initialProps)); + parameters.setProperty(runtime, "fabric", true); auto global = runtime.global(); auto registry = global.getProperty(runtime, "RN$AppRegistry"); @@ -49,7 +50,7 @@ void SurfaceRegistryBinding::startSurface( method.call( runtime, {jsi::String::createFromUtf8(runtime, moduleName), - jsi::valueFromDynamic(runtime, parameters), + std::move(parameters), jsi::Value(runtime, displayModeToInt(displayMode))}); } else { throwIfBridgeless(runtime, global, "startSurface"); @@ -58,7 +59,7 @@ void SurfaceRegistryBinding::startSurface( "AppRegistry", "runApplication", {jsi::String::createFromUtf8(runtime, moduleName), - jsi::valueFromDynamic(runtime, parameters), + std::move(parameters), jsi::Value(runtime, displayModeToInt(displayMode))}); } } @@ -70,10 +71,11 @@ void SurfaceRegistryBinding::setSurfaceProps( folly::dynamic const &initialProps, DisplayMode displayMode) { SystraceSection s("UIManagerBinding::setSurfaceProps"); - folly::dynamic parameters = folly::dynamic::object(); - parameters["rootTag"] = surfaceId; - parameters["initialProps"] = initialProps; - parameters["fabric"] = true; + jsi::Object parameters(runtime); + parameters.setProperty(runtime, "rootTag", surfaceId); + parameters.setProperty( + runtime, "initialProps", jsi::valueFromDynamic(runtime, initialProps)); + parameters.setProperty(runtime, "fabric", true); auto global = runtime.global(); auto registry = global.getProperty(runtime, "RN$AppRegistry"); @@ -83,7 +85,7 @@ void SurfaceRegistryBinding::setSurfaceProps( method.call( runtime, {jsi::String::createFromUtf8(runtime, moduleName), - jsi::valueFromDynamic(runtime, parameters), + std::move(parameters), jsi::Value(runtime, displayModeToInt(displayMode))}); } else { throwIfBridgeless(runtime, global, "setSurfaceProps"); @@ -92,7 +94,7 @@ void SurfaceRegistryBinding::setSurfaceProps( "AppRegistry", "setSurfaceProps", {jsi::String::createFromUtf8(runtime, moduleName), - jsi::valueFromDynamic(runtime, parameters), + std::move(parameters), jsi::Value(runtime, displayModeToInt(displayMode))}); } }