Skip to content

Commit 5b38bb4

Browse files
zeyapfacebook-github-bot
authored andcommitted
Avoid unnecessary copy of view props map in UIManager::updateShadowTree (#52908)
Summary: Pull Request resolved: #52908 ## Changelog: [General] [Changed] - Avoid unnecessary copy of view props map in UIManager::updateShadowTree Reviewed By: christophpurrer Differential Revision: D79193215 fbshipit-source-id: 6a55dc2bf3bcf95eebeeddf2d747fe11ae56bf78
1 parent 2dd72f9 commit 5b38bb4

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ class UIManager final : public ShadowTreeDelegate {
207207

208208
void reportMount(SurfaceId surfaceId) const;
209209

210-
void updateShadowTree(
211-
const std::unordered_map<Tag, folly::dynamic>& tagToProps);
210+
void updateShadowTree(std::unordered_map<Tag, folly::dynamic>&& tagToProps);
212211

213212
#pragma mark - Add & Remove event listener
214213

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerUpdateShadowTree.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ void addAncestorsToUpdateList(
8686
* license).
8787
*/
8888
void UIManager::updateShadowTree(
89-
const std::unordered_map<Tag, folly::dynamic>& tagToProps) {
89+
std::unordered_map<Tag, folly::dynamic>&& tagToProps) {
9090
const auto& contextContainer = *contextContainer_;
9191

92-
std::unordered_map<Tag, folly::dynamic> remainingTagToProps = tagToProps;
92+
auto remainingTagToProps = std::move(tagToProps);
93+
94+
if (delegate_ != nullptr) {
95+
delegate_->uiManagerDidUpdateShadowTree(remainingTagToProps);
96+
}
97+
9398
getShadowTreeRegistry().enumerate([&](const ShadowTree& shadowTree,
9499
bool& stop) {
95100
if (remainingTagToProps.empty()) {
@@ -219,10 +224,6 @@ void UIManager::updateShadowTree(
219224
LOG(ERROR) << "Root ShadowNode has not been cloned";
220225
}
221226
});
222-
223-
if (delegate_ != nullptr) {
224-
delegate_->uiManagerDidUpdateShadowTree(tagToProps);
225-
}
226227
}
227228

228229
} // namespace facebook::react

packages/react-native/ReactCxxPlatform/react/renderer/animated/MergedValueDispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MergedValueDispatcher {
2323
public:
2424
using DispatchFunction = std::function<void(std::function<void()>&&)>;
2525
using MergedValueFunction =
26-
std::function<void(std::unordered_map<Tag, folly::dynamic> tagToProps)>;
26+
std::function<void(std::unordered_map<Tag, folly::dynamic>&& tagToProps)>;
2727

2828
/**
2929
* Creates a MergedValueDispatcher with the given dispatch function.

packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManagerProvider.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ NativeAnimatedNodesManagerProvider::getOrCreate(
4949
[jsInvoker](std::function<void()>&& func) {
5050
jsInvoker->invokeAsync(std::move(func));
5151
},
52-
[uiManager](
53-
const std::unordered_map<Tag, folly::dynamic>& tagToProps) {
54-
uiManager->updateShadowTree(tagToProps);
52+
[uiManager](std::unordered_map<Tag, folly::dynamic>&& tagToProps) {
53+
uiManager->updateShadowTree(std::move(tagToProps));
5554
});
5655

5756
fabricCommitCallback =

0 commit comments

Comments
 (0)