Skip to content

Commit 6acfab7

Browse files
rubennortefacebook-github-bot
authored andcommitted
Remove incorrect const constraint from UIManager commit hooks
Summary: The `const` modified in UIManagerCommitHook prevents us from mutating the commit hook itself (which doesn't make any sense as commit hooks might want to update their internal state as response to new commits). This removes the constraint so we can remove the `const` modifier from `MutationObserverManager` in D46149086. Changelog: [internal] Reviewed By: sammy-SC Differential Revision: D46149085 fbshipit-source-id: e84c765535437a9877c2c53b1857b2be91c0db3e
1 parent 1e6f79d commit 6acfab7

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Scheduler::Scheduler(
114114
commitHooks_ = schedulerToolbox.commitHooks;
115115
uiManager_ = uiManager;
116116

117-
for (auto const &commitHook : commitHooks_) {
117+
for (auto &commitHook : commitHooks_) {
118118
uiManager->registerCommitHook(*commitHook);
119119
}
120120

@@ -147,7 +147,7 @@ Scheduler::~Scheduler() {
147147
LOG(WARNING) << "Scheduler::~Scheduler() was called (address: " << this
148148
<< ").";
149149

150-
for (auto const &commitHook : commitHooks_) {
150+
for (auto &commitHook : commitHooks_) {
151151
uiManager_->unregisterCommitHook(*commitHook);
152152
}
153153

packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Scheduler final : public UIManagerDelegate {
124124
std::shared_ptr<UIManager> uiManager_;
125125
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
126126

127-
std::vector<std::shared_ptr<UIManagerCommitHook const>> commitHooks_;
127+
std::vector<std::shared_ptr<UIManagerCommitHook>> commitHooks_;
128128

129129
/*
130130
* At some point, we have to have an owning shared pointer to something that

packages/react-native/ReactCommon/react/renderer/scheduler/SchedulerToolbox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct SchedulerToolbox final {
7575
/*
7676
* A list of `UIManagerCommitHook`s that should be registered in `UIManager`.
7777
*/
78-
std::vector<std::shared_ptr<UIManagerCommitHook const>> commitHooks;
78+
std::vector<std::shared_ptr<UIManagerCommitHook>> commitHooks;
7979
};
8080

8181
} // namespace facebook::react

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ ShadowTreeRegistry const &UIManager::getShadowTreeRegistry() const {
594594
return shadowTreeRegistry_;
595595
}
596596

597-
void UIManager::registerCommitHook(
598-
UIManagerCommitHook const &commitHook) const {
597+
void UIManager::registerCommitHook(UIManagerCommitHook &commitHook) {
599598
std::unique_lock lock(commitHookMutex_);
600599
react_native_assert(
601600
std::find(commitHooks_.begin(), commitHooks_.end(), &commitHook) ==
@@ -604,8 +603,7 @@ void UIManager::registerCommitHook(
604603
commitHooks_.push_back(&commitHook);
605604
}
606605

607-
void UIManager::unregisterCommitHook(
608-
UIManagerCommitHook const &commitHook) const {
606+
void UIManager::unregisterCommitHook(UIManagerCommitHook &commitHook) {
609607
std::unique_lock lock(commitHookMutex_);
610608
auto iterator =
611609
std::find(commitHooks_.begin(), commitHooks_.end(), &commitHook);
@@ -638,7 +636,7 @@ RootShadowNode::Unshared UIManager::shadowTreeWillCommit(
638636
std::shared_lock lock(commitHookMutex_);
639637

640638
auto resultRootShadowNode = newRootShadowNode;
641-
for (auto const *commitHook : commitHooks_) {
639+
for (auto *commitHook : commitHooks_) {
642640
resultRootShadowNode = commitHook->shadowTreeWillCommit(
643641
shadowTree, oldRootShadowNode, resultRootShadowNode);
644642
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class UIManager final : public ShadowTreeDelegate {
8080
/*
8181
* Registers and unregisters a commit hook.
8282
*/
83-
void registerCommitHook(UIManagerCommitHook const &commitHook) const;
84-
void unregisterCommitHook(UIManagerCommitHook const &commitHook) const;
83+
void registerCommitHook(UIManagerCommitHook &commitHook);
84+
void unregisterCommitHook(UIManagerCommitHook &commitHook);
8585

8686
/*
8787
* Registers and unregisters a mount hook.
@@ -224,7 +224,7 @@ class UIManager final : public ShadowTreeDelegate {
224224
ContextContainer::Shared contextContainer_;
225225

226226
mutable std::shared_mutex commitHookMutex_;
227-
mutable std::vector<UIManagerCommitHook const *> commitHooks_;
227+
mutable std::vector<UIManagerCommitHook *> commitHooks_;
228228

229229
mutable std::shared_mutex mountHookMutex_;
230230
mutable std::vector<UIManagerMountHook *> mountHooks_;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ class UIManagerCommitHook {
2222
/*
2323
* Called right after the commit hook is registered or unregistered.
2424
*/
25-
virtual void commitHookWasRegistered(
26-
UIManager const &uiManager) const noexcept = 0;
25+
virtual void commitHookWasRegistered(UIManager const &uiManager) noexcept = 0;
2726
virtual void commitHookWasUnregistered(
28-
UIManager const &uiManager) const noexcept = 0;
27+
UIManager const &uiManager) noexcept = 0;
2928

3029
/*
3130
* Called right before a `ShadowTree` commits a new tree.
@@ -35,7 +34,7 @@ class UIManagerCommitHook {
3534
virtual RootShadowNode::Unshared shadowTreeWillCommit(
3635
ShadowTree const &shadowTree,
3736
RootShadowNode::Shared const &oldRootShadowNode,
38-
RootShadowNode::Unshared const &newRootShadowNode) const noexcept = 0;
37+
RootShadowNode::Unshared const &newRootShadowNode) noexcept = 0;
3938

4039
virtual ~UIManagerCommitHook() noexcept = default;
4140
};

0 commit comments

Comments
 (0)