Skip to content

Commit

Permalink
Optimize arg conversion in SurfaceRegistryBinding (#39094)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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: d3efd60472103ce7c9d13646d0a9bf4164bf73e2
  • Loading branch information
javache authored and facebook-github-bot committed Aug 22, 2023
1 parent 4f8a8ce commit c22cc8f
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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))});
}
}
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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))});
}
}
Expand Down

0 comments on commit c22cc8f

Please sign in to comment.