From 730a0d5aefed0c60de1601a85b5e322894798e26 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Tue, 22 Jul 2025 22:06:34 -0700 Subject: [PATCH] Apply clang-tidy setting: react/renderer|perflogger (#52739) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52739 Changelog: [Internal] Reviewed By: rshest Differential Revision: D78634924 fbshipit-source-id: c0ad2c6162e1d5929b2b097b884f5989d040d576 --- .../ComponentDescriptorRegistry.cpp | 2 +- .../ComponentDescriptorRegistry.h | 3 ++- .../react/renderer/core/RawProps.cpp | 3 +-- .../react/renderer/core/RawProps.h | 2 +- .../react/renderer/core/RawPropsParser.cpp | 2 +- .../css/tests/CSSSyntaxParserTest.cpp | 6 ++--- .../renderer/mounting/stubs/StubView.cpp | 1 + .../renderer/mounting/stubs/StubViewTree.cpp | 5 ++-- .../tests/StateReconciliationTest.cpp | 6 ++--- .../IntersectionObserverManager.cpp | 2 +- .../mutation/MutationObserverManager.cpp | 8 +++---- .../mutation/MutationObserverManager.h | 8 +++---- .../tests/RuntimeSchedulerTest.cpp | 6 ++--- .../react/renderer/scheduler/Scheduler.cpp | 7 +++--- .../textlayoutmanager/TextLayoutManager.cpp | 4 ++-- .../uimanager/PointerHoverTracker.cpp | 4 ++-- .../react/renderer/uimanager/UIManager.cpp | 2 +- ...adowTreeRevisionConsistencyManagerTest.cpp | 4 ++-- .../tests/PointerEventsProcessorTest.cpp | 12 ++++------ .../BridgelessNativeMethodCallInvoker.cpp | 4 ++-- .../react/runtime/BufferedRuntimeExecutor.cpp | 2 +- .../react/runtime/ReactInstance.cpp | 23 +++++++++++-------- .../ReactCommon/react/runtime/ReactInstance.h | 3 +-- .../react/runtime/TimerManager.cpp | 20 ++++++++-------- .../runtime/tests/cxx/ReactInstanceTest.cpp | 23 ++++++++++--------- .../reactperflogger/fusebox/FuseboxTracer.cpp | 4 ++-- 26 files changed, 84 insertions(+), 82 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp b/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp index 595867a8948..38d19ba01e0 100644 --- a/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +++ b/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp @@ -29,7 +29,7 @@ ComponentDescriptorRegistry::ComponentDescriptorRegistry( contextContainer_(std::move(contextContainer)) {} void ComponentDescriptorRegistry::add( - ComponentDescriptorProvider componentDescriptorProvider) const { + const ComponentDescriptorProvider& componentDescriptorProvider) const { std::unique_lock lock(mutex_); auto componentDescriptor = componentDescriptorProvider.constructor( diff --git a/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.h b/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.h index ef520bd4bc9..641a99c384f 100644 --- a/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.h +++ b/packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.h @@ -71,7 +71,8 @@ class ComponentDescriptorRegistry { * To be used by `ComponentDescriptorProviderRegistry` only. * Thread safe. */ - void add(ComponentDescriptorProvider componentDescriptorProvider) const; + void add( + const ComponentDescriptorProvider& componentDescriptorProvider) const; mutable std::shared_mutex mutex_; mutable std::unordered_map diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp index 725d68ff371..f79f588f1f8 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawProps.cpp @@ -44,8 +44,7 @@ RawProps::RawProps(folly::dynamic dynamic) noexcept { dynamic_ = std::move(dynamic); } -RawProps::RawProps(const RawProps& other) noexcept { - mode_ = other.mode_; +RawProps::RawProps(const RawProps& other) noexcept : mode_(other.mode_) { if (mode_ == Mode::JSI) { runtime_ = other.runtime_; value_ = jsi::Value(*runtime_, other.value_); diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawProps.h b/packages/react-native/ReactCommon/react/renderer/core/RawProps.h index 31f15a3eaf2..75e8852ab6f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawProps.h +++ b/packages/react-native/ReactCommon/react/renderer/core/RawProps.h @@ -50,7 +50,7 @@ class RawProps final { */ RawProps(jsi::Runtime& runtime, const jsi::Value& value) noexcept; - explicit RawProps(const RawProps& rawProps) noexcept; + explicit RawProps(const RawProps& other) noexcept; RawProps(RawProps&& other) noexcept = default; RawProps& operator=(const RawProps& other) noexcept = delete; diff --git a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp index f39a1d59a34..aaf9519897f 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/RawPropsParser.cpp @@ -164,7 +164,7 @@ void RawPropsParser::preparse(const RawProps& rawProps) const noexcept { } rawProps.keyIndexToValueIndex_[keyIndex] = valueIndex; - rawProps.values_.push_back(RawValue{pair.second}); + rawProps.values_.emplace_back(pair.second); valueIndex++; } break; diff --git a/packages/react-native/ReactCommon/react/renderer/css/tests/CSSSyntaxParserTest.cpp b/packages/react-native/ReactCommon/react/renderer/css/tests/CSSSyntaxParserTest.cpp index 494d4fc464e..3f2e7ac5687 100644 --- a/packages/react-native/ReactCommon/react/renderer/css/tests/CSSSyntaxParserTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/css/tests/CSSSyntaxParserTest.cpp @@ -492,7 +492,7 @@ TEST(CSSSyntaxParser, solidus_or_whitespace) { auto delimValue1 = parser.consumeComponentValue( CSSDelimiter::SolidusOrWhitespace, - [](const CSSPreservedToken& token) { return true; }); + [](const CSSPreservedToken& /*token*/) { return true; }); EXPECT_FALSE(delimValue1); } @@ -549,8 +549,8 @@ TEST(CSSSyntaxParser, component_value_not_consumed_on_visitor_failure) { EXPECT_TRUE(visitor2Attempted); bool visitor3Attempted = false; - bool visitor3Ret = - parser.consumeComponentValue([&](const CSSPreservedToken& token) { + bool visitor3Ret = parser.consumeComponentValue( + [&](const CSSPreservedToken& /*token*/) { visitor3Attempted = true; return true; }); diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubView.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubView.cpp index dd40d1ed9aa..2075f046cb6 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubView.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubView.cpp @@ -88,6 +88,7 @@ std::vector getDebugChildren( const StubView& stubView, DebugStringConvertibleOptions /*options*/) { std::vector result; + result.reserve(stubView.children.size()); for (const auto& child : stubView.children) { result.push_back(*child); } diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp index 1ee628ab3e1..1b919eab8ec 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/stubs/StubViewTree.cpp @@ -26,10 +26,11 @@ std::string getComponentName(const ShadowView& shadowView) { } } // namespace -StubViewTree::StubViewTree(const ShadowView& shadowView) { +StubViewTree::StubViewTree(const ShadowView& shadowView) + : rootTag_(shadowView.tag) { auto view = std::make_shared(); view->update(shadowView); - rootTag_ = shadowView.tag; + registry_[shadowView.tag] = view; } diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp index 70d762b516c..7290d76cc63 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp @@ -32,11 +32,11 @@ class DummyShadowTreeDelegate : public ShadowTreeDelegate { const RootShadowNode::Unshared& newRootShadowNode, const ShadowTree::CommitOptions& /*commitOptions*/) const override { return newRootShadowNode; - }; + } void shadowTreeDidFinishTransaction( std::shared_ptr mountingCoordinator, - bool mountSynchronously) const override {}; + bool /*mountSynchronously*/) const override {} }; namespace { @@ -47,7 +47,7 @@ const ShadowNode* findDescendantNode( return &shadowNode; } - for (auto childNode : shadowNode.getChildren()) { + for (const auto& childNode : shadowNode.getChildren()) { auto descendant = findDescendantNode(*childNode, family); if (descendant != nullptr) { return descendant; diff --git a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp index 63060798cf4..e1da54819ca 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/intersection/IntersectionObserverManager.cpp @@ -44,7 +44,7 @@ void IntersectionObserverManager::observe( const ShadowNodeFamily::Shared& shadowNodeFamily, std::vector thresholds, std::optional> rootThresholds, - const UIManager& uiManager) { + const UIManager& /*uiManager*/) { TraceSection s("IntersectionObserverManager::observe"); auto surfaceId = shadowNodeFamily->getSurfaceId(); 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 a54aefc6227..54fa858e3d0 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.cpp @@ -18,7 +18,7 @@ void MutationObserverManager::observe( MutationObserverId mutationObserverId, std::shared_ptr shadowNode, bool observeSubtree, - const UIManager& uiManager) { + const UIManager& /*uiManager*/) { TraceSection s("MutationObserverManager::observe"); auto surfaceId = shadowNode->getSurfaceId(); @@ -55,7 +55,7 @@ void MutationObserverManager::unobserveAll( void MutationObserverManager::connect( UIManager& uiManager, - std::function&)> onMutations) { + OnMutations&& onMutations) { TraceSection s("MutationObserverManager::connect"); // Fail-safe in case the caller doesn't guarantee consistency. @@ -63,7 +63,7 @@ void MutationObserverManager::connect( return; } - onMutations_ = onMutations; + onMutations_ = std::move(onMutations); uiManager.registerCommitHook(*this); commitHookRegistered_ = true; @@ -123,8 +123,6 @@ void MutationObserverManager::runMutationObservations( if (!mutationRecords.empty()) { onMutations_(mutationRecords); } - - return; } } // namespace facebook::react 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 791d7c550a7..53021433069 100644 --- a/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h +++ b/packages/react-native/ReactCommon/react/renderer/observers/mutation/MutationObserverManager.h @@ -16,6 +16,8 @@ namespace facebook::react { +using OnMutations = std::function&)>; + class MutationObserverManager final : public UIManagerCommitHook { public: MutationObserverManager(); @@ -28,9 +30,7 @@ class MutationObserverManager final : public UIManagerCommitHook { void unobserveAll(MutationObserverId mutationObserverId); - void connect( - UIManager& uiManager, - std::function&)> onMutations); + void connect(UIManager& uiManager, OnMutations&& onMutations); void disconnect(UIManager& uiManager); @@ -51,7 +51,7 @@ class MutationObserverManager final : public UIManagerCommitHook { std::unordered_map> observersBySurfaceId_; - std::function&)> onMutations_; + OnMutations onMutations_; bool commitHookRegistered_{}; void runMutationObservations( diff --git a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp index aa2340f98fb..3cbb84532e6 100644 --- a/packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/runtimescheduler/tests/RuntimeSchedulerTest.cpp @@ -187,7 +187,7 @@ TEST_P( 3, [&](jsi::Runtime& /*unused*/, const jsi::Value& /*unused*/, - const jsi::Value* arguments, + const jsi::Value* /*arguments*/, size_t /*unused*/) -> jsi::Value { microtaskPosition = nextOperationPosition; nextOperationPosition++; @@ -906,7 +906,7 @@ TEST_P(RuntimeSchedulerTest, sameThreadTaskCreatesImmediatePriorityTask) { std::thread t1([this, &didRunSynchronousTask, &didRunSubsequentTask]() { runtimeScheduler_->executeNowOnTheSameThread( [this, &didRunSynchronousTask, &didRunSubsequentTask]( - jsi::Runtime& runtime) { + jsi::Runtime& /*runtime*/) { didRunSynchronousTask = true; auto callback = createHostFunctionFromLambda( @@ -994,7 +994,7 @@ TEST_P(RuntimeSchedulerTest, sameThreadTaskCreatesLowPriorityTask) { std::thread t1([this, &didRunSynchronousTask, &didRunSubsequentTask]() { runtimeScheduler_->executeNowOnTheSameThread( [this, &didRunSynchronousTask, &didRunSubsequentTask]( - jsi::Runtime& runtime) { + jsi::Runtime& /*runtime*/) { didRunSynchronousTask = true; auto callback = createHostFunctionFromLambda( diff --git a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp index 46333c2ca77..45d2bab5f9b 100644 --- a/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/packages/react-native/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -27,10 +27,9 @@ namespace facebook::react { Scheduler::Scheduler( const SchedulerToolbox& schedulerToolbox, UIManagerAnimationDelegate* animationDelegate, - SchedulerDelegate* delegate) { - runtimeExecutor_ = schedulerToolbox.runtimeExecutor; - contextContainer_ = schedulerToolbox.contextContainer; - + SchedulerDelegate* delegate) + : runtimeExecutor_(schedulerToolbox.runtimeExecutor), + contextContainer_(schedulerToolbox.contextContainer) { // Creating a container for future `EventDispatcher` instance. eventDispatcher_ = std::make_shared>(); diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp index 10232b8054b..7c1782826b6 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/android/react/renderer/textlayoutmanager/TextLayoutManager.cpp @@ -156,7 +156,7 @@ TextMeasurement doMeasure( TextLayoutManager::TextLayoutManager( const std::shared_ptr& contextContainer) - : contextContainer_(contextContainer), + : contextContainer_(std::move(contextContainer)), textMeasureCache_(kSimpleThreadSafeCacheSizeCap), lineMeasureCache_(kSimpleThreadSafeCacheSizeCap), preparedTextCache_(static_cast( @@ -236,7 +236,7 @@ TextMeasurement TextLayoutManager::measureCachedSpannableById( // TODO: currently we do not support attachments for cached IDs - should we? auto attachments = TextMeasurement::Attachments{}; - return TextMeasurement{size, attachments}; + return TextMeasurement{.size = size, .attachments = attachments}; } LinesMeasurements TextLayoutManager::measureLines( diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/PointerHoverTracker.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/PointerHoverTracker.cpp index 5c206d904d5..10d1e785fcd 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/PointerHoverTracker.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/PointerHoverTracker.cpp @@ -93,7 +93,7 @@ std::tuple PointerHoverTracker::diffEventPath( for (auto nodeIt = myIt; nodeIt != myEventPath.rend(); nodeIt++) { const auto& latestNode = getLatestNode(*nodeIt, uiManager); if (latestNode != nullptr) { - removed.push_back(*latestNode); + removed.emplace_back(*latestNode); } } @@ -101,7 +101,7 @@ std::tuple PointerHoverTracker::diffEventPath( for (auto nodeIt = otherIt; nodeIt != otherEventPath.rend(); nodeIt++) { const auto& latestNode = other.getLatestNode(*nodeIt, uiManager); if (latestNode != nullptr) { - added.push_back(*latestNode); + added.emplace_back(*latestNode); } } diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp index e347e8ff3b3..4855071d9ab 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp @@ -516,7 +516,7 @@ std::shared_ptr UIManager::findShadowNodeByTag_DEPRECATED( auto shadowNode = std::shared_ptr{}; shadowTreeRegistry_.enumerate([&](const ShadowTree& shadowTree, bool& stop) { - const RootShadowNode* rootShadowNode; + const RootShadowNode* rootShadowNode = nullptr; // The public interface of `ShadowTree` discourages accessing a stored // pointer to a root node because of the possible data race. // To work around this, we ask for a commit and immediately cancel it diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/consistency/tests/LazyShadowTreeRevisionConsistencyManagerTest.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/consistency/tests/LazyShadowTreeRevisionConsistencyManagerTest.cpp index 2c1076ae278..01d43d096c5 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/consistency/tests/LazyShadowTreeRevisionConsistencyManagerTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/consistency/tests/LazyShadowTreeRevisionConsistencyManagerTest.cpp @@ -22,11 +22,11 @@ class FakeShadowTreeDelegate : public ShadowTreeDelegate { const RootShadowNode::Unshared& newRootShadowNode, const ShadowTree::CommitOptions& /*commitOptions*/) const override { return newRootShadowNode; - }; + } void shadowTreeDidFinishTransaction( std::shared_ptr mountingCoordinator, - bool mountSynchronously) const override {}; + bool /*mountSynchronously*/) const override {} }; class LazyShadowTreeRevisionConsistencyManagerTest : public ::testing::Test { diff --git a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp index 358a91f843e..09cb2c170a9 100644 --- a/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/uimanager/tests/PointerEventsProcessorTest.cpp @@ -36,8 +36,6 @@ static inline void listenToAllPointerEvents(ViewProps& props) { class PointerEventsProcessorTest : public ::testing::Test { public: PointerEventsProcessorTest() { - surfaceId_ = 0; - auto contextContainer = std::make_shared(); ComponentDescriptorProviderRegistry componentDescriptorProviderRegistry{}; @@ -180,7 +178,7 @@ class PointerEventsProcessorTest : public ::testing::Test { *uiManager_, *contextContainer); shadowTree->commit( - [this](const RootShadowNode& oldRootShadowNode) { + [this](const RootShadowNode& /*oldRootShadowNode*/) { return std::static_pointer_cast(this->rootNode_); }, {true}); @@ -199,13 +197,13 @@ class PointerEventsProcessorTest : public ::testing::Test { EventLog dispatchPointerEvent( const std::shared_ptr& target, - std::string eventName, - PointerEvent eventPayload) { + const std::string& eventName, + const PointerEvent& eventPayload) { EventLog eventLog; auto dispatchCallback = [&eventLog]( const ShadowNode& targetNode, const std::string& type, - ReactEventPriority priority, + ReactEventPriority /*priority*/, const EventPayload& eventPayload) { eventLog.push_back({ .tag = targetNode.getTag(), @@ -223,7 +221,7 @@ class PointerEventsProcessorTest : public ::testing::Test { return eventLog; } - SurfaceId surfaceId_; + SurfaceId surfaceId_{0}; std::shared_ptr rootNode_; std::shared_ptr nodeA_; diff --git a/packages/react-native/ReactCommon/react/runtime/BridgelessNativeMethodCallInvoker.cpp b/packages/react-native/ReactCommon/react/runtime/BridgelessNativeMethodCallInvoker.cpp index f81cba0e9e1..f9f49bf9e5b 100644 --- a/packages/react-native/ReactCommon/react/runtime/BridgelessNativeMethodCallInvoker.cpp +++ b/packages/react-native/ReactCommon/react/runtime/BridgelessNativeMethodCallInvoker.cpp @@ -14,13 +14,13 @@ BridgelessNativeMethodCallInvoker::BridgelessNativeMethodCallInvoker( : messageQueueThread_(std::move(messageQueueThread)) {} void BridgelessNativeMethodCallInvoker::invokeAsync( - const std::string& methodName, + const std::string& /*methodName*/, NativeMethodCallFunc&& func) noexcept { messageQueueThread_->runOnQueue(std::move(func)); } void BridgelessNativeMethodCallInvoker::invokeSync( - const std::string& methodName, + const std::string& /*methodName*/, NativeMethodCallFunc&& func) { messageQueueThread_->runOnQueueSync(std::move(func)); } diff --git a/packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.cpp b/packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.cpp index 389cbbc16a5..db6dc089b6e 100644 --- a/packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.cpp +++ b/packages/react-native/ReactCommon/react/runtime/BufferedRuntimeExecutor.cpp @@ -47,7 +47,7 @@ void BufferedRuntimeExecutor::flush() { } void BufferedRuntimeExecutor::unsafeFlush() { - while (queue_.size() > 0) { + while (!queue_.empty()) { const BufferedWork& bufferedWork = queue_.top(); Work work = bufferedWork.work_; runtimeExecutor_(std::move(work)); diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp index b4c8b1b50fe..5907299703e 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp @@ -36,7 +36,9 @@ std::shared_ptr createRuntimeScheduler( RuntimeSchedulerTaskErrorHandler taskErrorHandler) { std::shared_ptr scheduler = std::make_shared( - runtimeExecutor, HighResTimeStamp::now, taskErrorHandler); + std::move(runtimeExecutor), + HighResTimeStamp::now, + std::move(taskErrorHandler)); scheduler->setPerformanceEntryReporter( // FIXME: Move creation of PerformanceEntryReporter to here and // guarantee that its lifetime is the same as the runtime. @@ -54,7 +56,7 @@ ReactInstance::ReactInstance( JsErrorHandler::OnJsError onJsError, jsinspector_modern::HostTarget* parentInspectorTarget) : runtime_(std::move(runtime)), - jsMessageQueueThread_(jsMessageQueueThread), + jsMessageQueueThread_(std::move(jsMessageQueueThread)), timerManager_(std::move(timerManager)), jsErrorHandler_(std::make_shared(std::move(onJsError))), parentInspectorTarget_(parentInspectorTarget) { @@ -93,7 +95,7 @@ ReactInstance::ReactInstance( } }; - if (parentInspectorTarget_) { + if (parentInspectorTarget_ != nullptr) { auto executor = parentInspectorTarget_->executorFromThis(); auto bufferedRuntimeExecutorThatWaitsForInspectorSetup = @@ -155,7 +157,7 @@ ReactInstance::ReactInstance( } void ReactInstance::unregisterFromInspector() { - if (inspectorTarget_) { + if (inspectorTarget_ != nullptr) { assert(runtimeInspectorTarget_); inspectorTarget_->unregisterRuntime(*runtimeInspectorTarget_); @@ -234,7 +236,7 @@ void ReactInstance::loadScript( beforeLoad(runtime); } TraceSection s("ReactInstance::loadScript"); - bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl); + bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl != nullptr); if (hasLogger) { ReactMarker::logTaggedMarkerBridgeless( ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str()); @@ -344,7 +346,7 @@ void ReactInstance::registerSegment( } auto buffer = std::make_shared(std::move(script)); - bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl); + bool hasLogger(ReactMarker::logTaggedMarkerBridgelessImpl != nullptr); if (hasLogger) { ReactMarker::logTaggedMarkerBridgeless( ReactMarker::REGISTER_JS_SEGMENT_START, tag.c_str()); @@ -365,7 +367,7 @@ void ReactInstance::registerSegment( namespace { void defineReactInstanceFlags( jsi::Runtime& runtime, - ReactInstance::JSRuntimeFlags options) noexcept { + const ReactInstance::JSRuntimeFlags& options) noexcept { defineReadOnlyGlobal(runtime, "RN$Bridgeless", jsi::Value(true)); if (options.isProfiling) { @@ -390,7 +392,10 @@ bool isTruthy(jsi::Runtime& runtime, const jsi::Value& value) { void ReactInstance::initializeRuntime( JSRuntimeFlags options, BindingsInstallFunc bindingsInstallFunc) noexcept { - runtimeScheduler_->scheduleWork([this, options, bindingsInstallFunc]( + runtimeScheduler_->scheduleWork([this, + options = std::move(options), + bindingsInstallFunc = + std::move(bindingsInstallFunc)]( jsi::Runtime& runtime) { TraceSection s("ReactInstance::initializeRuntime"); @@ -606,7 +611,7 @@ void ReactInstance::handleMemoryPressureJs(int pressureLevel) { TRIM_MEMORY_RUNNING_MODERATE = 5, TRIM_MEMORY_UI_HIDDEN = 20, }; - const char* levelName; + const char* levelName = nullptr; switch (pressureLevel) { case TRIM_MEMORY_BACKGROUND: levelName = "TRIM_MEMORY_BACKGROUND"; diff --git a/packages/react-native/ReactCommon/react/runtime/ReactInstance.h b/packages/react-native/ReactCommon/react/runtime/ReactInstance.h index 0221ce1f55d..3c92b268f38 100644 --- a/packages/react-native/ReactCommon/react/runtime/ReactInstance.h +++ b/packages/react-native/ReactCommon/react/runtime/ReactInstance.h @@ -18,7 +18,6 @@ #include #include #include -#include namespace facebook::react { @@ -41,7 +40,7 @@ class ReactInstance final : private jsinspector_modern::InstanceTargetDelegate { struct JSRuntimeFlags { bool isProfiling = false; - const std::string runtimeDiagnosticFlags = ""; + const std::string runtimeDiagnosticFlags; }; void initializeRuntime( diff --git a/packages/react-native/ReactCommon/react/runtime/TimerManager.cpp b/packages/react-native/ReactCommon/react/runtime/TimerManager.cpp index 805c8a6f1f3..e312c21804e 100644 --- a/packages/react-native/ReactCommon/react/runtime/TimerManager.cpp +++ b/packages/react-native/ReactCommon/react/runtime/TimerManager.cpp @@ -59,7 +59,7 @@ TimerManager::TimerManager( void TimerManager::setRuntimeExecutor( RuntimeExecutor runtimeExecutor) noexcept { - runtimeExecutor_ = runtimeExecutor; + runtimeExecutor_ = std::move(runtimeExecutor); } TimerHandle TimerManager::createReactNativeMicrotask( @@ -232,7 +232,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 3, // Function, delay, ...args [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count == 0) { @@ -272,7 +272,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 1, // timerID [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count > 0 && args[0].isNumber()) { @@ -291,7 +291,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 3, // Function, delay, ...args [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count == 0) { @@ -332,7 +332,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 1, // timerID [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count > 0 && args[0].isNumber()) { @@ -351,7 +351,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 1, // callback [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count == 0) { @@ -373,9 +373,9 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { [callbackContainer = std::make_shared( args[0].getObject(rt).getFunction(rt))]( jsi::Runtime& rt, - const jsi::Value& thisVal, - const jsi::Value* args, - size_t count) { + const jsi::Value& /*thisVal*/, + const jsi::Value* /*args*/, + size_t /*count*/) { auto performance = rt.global().getPropertyAsObject(rt, "performance"); auto nowFn = performance.getPropertyAsFunction(rt, "now"); @@ -402,7 +402,7 @@ void TimerManager::attachGlobals(jsi::Runtime& runtime) { 1, // timerID [this]( jsi::Runtime& rt, - const jsi::Value& thisVal, + const jsi::Value& /*thisVal*/, const jsi::Value* args, size_t count) { if (count > 0 && args[0].isNumber()) { diff --git a/packages/react-native/ReactCommon/react/runtime/tests/cxx/ReactInstanceTest.cpp b/packages/react-native/ReactCommon/react/runtime/tests/cxx/ReactInstanceTest.cpp index 63b5aa4a385..8d39ace3f5f 100644 --- a/packages/react-native/ReactCommon/react/runtime/tests/cxx/ReactInstanceTest.cpp +++ b/packages/react-native/ReactCommon/react/runtime/tests/cxx/ReactInstanceTest.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -32,15 +33,15 @@ class MockTimerRegistry : public PlatformTimerRegistry { class MockMessageQueueThread : public MessageQueueThread { public: - void runOnQueue(std::function&& func) { + void runOnQueue(std::function&& func) override { callbackQueue_.push(func); } // Unused - void runOnQueueSync(std::function&&) {} + void runOnQueueSync(std::function&& /*unused*/) override {} // Unused - void quitSynchronous() {} + void quitSynchronous() override {} void tick() { if (!callbackQueue_.empty()) { @@ -79,7 +80,7 @@ class ErrorUtils : public jsi::HostObject { 1, [this]( jsi::Runtime& runtime, - const jsi::Value& thisValue, + const jsi::Value& /*thisValue*/, const jsi::Value* arguments, size_t count) { if (count >= 1) { @@ -114,7 +115,7 @@ class ErrorUtils : public jsi::HostObject { class ReactInstanceTest : public ::testing::Test { protected: - ReactInstanceTest() {} + ReactInstanceTest() = default; void SetUp() override { auto runtime = @@ -152,7 +153,7 @@ class ReactInstanceTest : public ::testing::Test { step(); // Run the main bundle, so that native -> JS calls no longer get buffered. - loadScript(script); + loadScript(std::move(script)); } void initializeRuntimeWithScript(std::string script) { @@ -161,16 +162,16 @@ class ReactInstanceTest : public ::testing::Test { step(); // Run the main bundle, so that native -> JS calls no longer get buffered. - loadScript(script); + loadScript(std::move(script)); } - jsi::Value tryEval(std::string js, std::string defaultVal) { + jsi::Value tryEval(const std::string& js, const std::string& defaultVal) { return eval( "(function() { try { return " + js + "; } catch { return " + defaultVal + "; } })()"); } - jsi::Value eval(std::string js) { + jsi::Value eval(const std::string& js) { RuntimeExecutor runtimeExecutor = instance_->getUnbufferedRuntimeExecutor(); jsi::Value ret = jsi::Value::undefined(); runtimeExecutor([js, &ret](jsi::Runtime& runtime) { @@ -214,11 +215,11 @@ class ReactInstanceTest : public ::testing::Test { messageQueueThread_->guardedTick(); } - jsi::Runtime* runtime_; + jsi::Runtime* runtime_{}; std::shared_ptr messageQueueThread_; std::unique_ptr instance_; std::shared_ptr timerManager_; - MockTimerRegistry* mockRegistry_; + MockTimerRegistry* mockRegistry_{}; std::shared_ptr errorHandler_; }; diff --git a/packages/react-native/ReactCommon/reactperflogger/fusebox/FuseboxTracer.cpp b/packages/react-native/ReactCommon/reactperflogger/fusebox/FuseboxTracer.cpp index 3d52288965c..b08572ddc37 100644 --- a/packages/react-native/ReactCommon/reactperflogger/fusebox/FuseboxTracer.cpp +++ b/packages/react-native/ReactCommon/reactperflogger/fusebox/FuseboxTracer.cpp @@ -70,7 +70,7 @@ bool FuseboxTracer::stopTracing( for (auto& event : savedBuffer) { // For events with a custom track name, register track - if (event.track.length() && !trackIdMap.contains(event.track)) { + if (!event.track.empty() && !trackIdMap.contains(event.track)) { auto trackId = nextTrack++; trackIdMap[event.track] = trackId; traceEvents.push_back(folly::dynamic::object( @@ -94,7 +94,7 @@ bool FuseboxTracer::stopTracing( } } - if (traceEvents.size() >= 1) { + if (!traceEvents.empty()) { resultCallback(traceEvents); } return true;