From 9b6e2d21d12b4d327f7faecaf6f2d61cdaf31156 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Mon, 23 Oct 2023 15:52:06 -0700 Subject: [PATCH] Eliminate const qualifier from MutationRecord (#41162) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41162 "The C++ standard forbids containers of const elements because allocator is ill-formed." We have a few other callsites for std::vector, but the const values are always const pointers, which I guess are okay? Suffice to say, this doesn't compile with Microsoft STL headers unless you remove const. ## Changelog [Internal] Reviewed By: javache Differential Revision: D50563174 fbshipit-source-id: 96053baedc41237d8d27a1e01ac94ce5abd6c768 --- .../Libraries/MutationObserver/NativeMutationObserver.cpp | 5 ++--- .../Libraries/MutationObserver/NativeMutationObserver.h | 2 +- .../react/renderer/observers/mutation/MutationObserver.cpp | 6 +++--- .../react/renderer/observers/mutation/MutationObserver.h | 6 +++--- .../renderer/observers/mutation/MutationObserverManager.cpp | 4 ++-- .../renderer/observers/mutation/MutationObserverManager.h | 4 ++-- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.cpp b/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.cpp index a491e3e47e6..c725c36252f 100644 --- a/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.cpp +++ b/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.cpp @@ -88,7 +88,7 @@ void NativeMutationObserver::connect( notifyMutationObservers_ = std::move(notifyMutationObservers); - auto onMutationsCallback = [&](std::vector& records) { + auto onMutationsCallback = [&](std::vector& records) { return onMutations(records); }; @@ -125,8 +125,7 @@ NativeMutationObserver::getPublicInstancesFromShadowNodes( return publicInstances; } -void NativeMutationObserver::onMutations( - std::vector& records) { +void NativeMutationObserver::onMutations(std::vector& records) { SystraceSection s("NativeMutationObserver::onMutations"); for (const auto& record : records) { diff --git a/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.h b/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.h index 218ad1714a8..cbf7120a49d 100644 --- a/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.h +++ b/packages/react-native/Libraries/MutationObserver/NativeMutationObserver.h @@ -94,7 +94,7 @@ class NativeMutationObserver bool notifiedMutationObservers_{}; std::function notifyMutationObservers_; - void onMutations(std::vector& records); + void onMutations(std::vector& records); void notifyMutationObserversIfNecessary(); std::vector getPublicInstancesFromShadowNodes( diff --git a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.cpp b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.cpp index c24db979c15..4946c1c3e8a 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.cpp @@ -77,7 +77,7 @@ static ShadowNode::Shared findNodeOfSameFamily( void MutationObserver::recordMutations( const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, - std::vector& recordedMutations) const { + std::vector& recordedMutations) const { // This tracks the nodes that have already been processed by this observer, // so we avoid unnecessary work and duplicated entries. SetOfShadowNodePointers processedNodes; @@ -110,7 +110,7 @@ void MutationObserver::recordMutationsInTarget( const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, bool observeSubtree, - std::vector& recordedMutations, + std::vector& recordedMutations, SetOfShadowNodePointers& processedNodes) const { // If the node isnt't present in the old tree, it's either: // - A new node. In that case, the mutation happened in its parent, not in the @@ -146,7 +146,7 @@ void MutationObserver::recordMutationsInSubtrees( const ShadowNode& oldNode, const ShadowNode& newNode, bool observeSubtree, - std::vector& recordedMutations, + std::vector& recordedMutations, SetOfShadowNodePointers processedNodes) const { bool isSameNode = &oldNode == &newNode; // If the nodes are referentially equal, their children are also the same. diff --git a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.h b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.h index 02d539c85d3..2e05cfc0e57 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.h +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserver.h @@ -35,7 +35,7 @@ class MutationObserver { void recordMutations( const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, - std::vector& recordedMutations) const; + std::vector& recordedMutations) const; private: MutationObserverId mutationObserverId_; @@ -49,7 +49,7 @@ class MutationObserver { const RootShadowNode& oldRootShadowNode, const RootShadowNode& newRootShadowNode, bool observeSubtree, - std::vector& recordedMutations, + std::vector& recordedMutations, SetOfShadowNodePointers& processedNodes) const; void recordMutationsInSubtrees( @@ -57,7 +57,7 @@ class MutationObserver { const ShadowNode& oldNode, const ShadowNode& newNode, bool observeSubtree, - std::vector& recordedMutations, + std::vector& recordedMutations, SetOfShadowNodePointers processedNodes) const; }; diff --git a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp index 681884ef40e..8403a2757e6 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp @@ -70,7 +70,7 @@ void MutationObserverManager::unobserve( void MutationObserverManager::connect( UIManager& uiManager, - std::function&)> onMutations) { + std::function&)> onMutations) { SystraceSection s("MutationObserverManager::connect"); // Fail-safe in case the caller doesn't guarantee consistency. @@ -124,7 +124,7 @@ void MutationObserverManager::runMutationObservations( return; } - std::vector mutationRecords; + std::vector mutationRecords; auto& observers = observersIt->second; for (const auto& [mutationObserverId, observer] : observers) { diff --git a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h index 25c3751c89f..60c53116c81 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h @@ -31,7 +31,7 @@ class MutationObserverManager final : public UIManagerCommitHook { void connect( UIManager& uiManager, - std::function&)> onMutations); + std::function&)> onMutations); void disconnect(UIManager& uiManager); @@ -51,7 +51,7 @@ class MutationObserverManager final : public UIManagerCommitHook { std::unordered_map> observersBySurfaceId_; - std::function&)> onMutations_; + std::function&)> onMutations_; bool commitHookRegistered_{}; void runMutationObservations(