Skip to content

Commit 3caac1a

Browse files
rubennortefacebook-github-bot
authored andcommitted
Remove incorrect const constraint from UIManager commit hooks (#37588)
Summary: Pull Request resolved: #37588 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 a future diff. Changelog: [internal] Reviewed By: sammy-SC Differential Revision: D46149085 fbshipit-source-id: e348479c4b5b3d864f7be9133588b0a5eedc8452
1 parent f9db8b9 commit 3caac1a

File tree

8 files changed

+19
-25
lines changed

8 files changed

+19
-25
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/timeline/TimelineController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ void TimelineController::disable(TimelineHandler &&handler) const {
4242
}
4343

4444
void TimelineController::commitHookWasRegistered(
45-
UIManager const &uiManager) const noexcept {
45+
UIManager const &uiManager) noexcept {
4646
uiManager_ = &uiManager;
4747
}
4848

4949
void TimelineController::commitHookWasUnregistered(
50-
UIManager const & /*uiManager*/) const noexcept {
50+
UIManager const & /*uiManager*/) noexcept {
5151
uiManager_ = nullptr;
5252
}
5353

5454
RootShadowNode::Unshared TimelineController::shadowTreeWillCommit(
5555
ShadowTree const &shadowTree,
5656
RootShadowNode::Shared const &oldRootShadowNode,
57-
RootShadowNode::Unshared const &newRootShadowNode) const noexcept {
57+
RootShadowNode::Unshared const &newRootShadowNode) noexcept {
5858
std::shared_lock<std::shared_mutex> lock(timelinesMutex_);
5959

6060
assert(uiManager_ && "`uiManager_` must not be `nullptr`.");

packages/react-native/ReactCommon/react/renderer/timeline/TimelineController.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,11 @@ class TimelineController final : public UIManagerCommitHook {
5252
RootShadowNode::Unshared shadowTreeWillCommit(
5353
ShadowTree const &shadowTree,
5454
RootShadowNode::Shared const &oldRootShadowNode,
55-
RootShadowNode::Unshared const &newRootShadowNode)
56-
const noexcept override;
55+
RootShadowNode::Unshared const &newRootShadowNode) noexcept override;
5756

58-
void commitHookWasRegistered(
59-
UIManager const &uiManager) const noexcept override;
57+
void commitHookWasRegistered(UIManager const &uiManager) noexcept override;
6058

61-
void commitHookWasUnregistered(
62-
UIManager const &uiManager) const noexcept override;
59+
void commitHookWasUnregistered(UIManager const &uiManager) noexcept override;
6360

6461
private:
6562
/*

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)