From 3af0bad22a9f6200fcfc09534f5c0925ad63271c Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 13 Sep 2024 14:54:43 +0200 Subject: [PATCH] Pass shared_ptr<> arguments by const reference These arguments are not expensive to copy. However, it makes sense to pass such pointers by const reference when they are just intended for reading. Some reading about this issue is here: https://www.internalpointers.com/post/move-smart-pointers-and-out-functions-modern-c Fixes some Coverity scan defects. --- src/TocBuilder.cpp | 2 +- src/TocBuilder.h | 2 +- src/frontends/qt/Action.cpp | 2 +- src/frontends/qt/Action.h | 2 +- src/frontends/qt/TocModel.cpp | 2 +- src/frontends/qt/TocModel.h | 2 +- src/support/FileMonitor.cpp | 4 ++-- src/support/FileMonitor.h | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/TocBuilder.cpp b/src/TocBuilder.cpp index 1cfeddc450..fb688bd58e 100644 --- a/src/TocBuilder.cpp +++ b/src/TocBuilder.cpp @@ -24,7 +24,7 @@ namespace lyx { -TocBuilder::TocBuilder(shared_ptr toc) +TocBuilder::TocBuilder(shared_ptr const & toc) : toc_(toc ? toc : make_shared()), stack_() { diff --git a/src/TocBuilder.h b/src/TocBuilder.h index 5c3407918a..eca655ca16 100644 --- a/src/TocBuilder.h +++ b/src/TocBuilder.h @@ -27,7 +27,7 @@ class DocIterator; class TocBuilder { public: - TocBuilder(std::shared_ptr toc); + TocBuilder(std::shared_ptr const & toc); /// Open a level. /// When entering a float or flex or paragraph (with AddToToc) void pushItem(DocIterator const & dit, docstring const & s, diff --git a/src/frontends/qt/Action.cpp b/src/frontends/qt/Action.cpp index 818aca0f07..3d3eafa240 100644 --- a/src/frontends/qt/Action.cpp +++ b/src/frontends/qt/Action.cpp @@ -40,7 +40,7 @@ Action::Action(FuncRequest func, QIcon const & icon, QString const & text, } -Action::Action(shared_ptr func, +Action::Action(shared_ptr const & func, QIcon const & icon, QString const & text, QString const & tooltip, QObject * parent) : QAction(parent), func_(func), icon_(icon) diff --git a/src/frontends/qt/Action.h b/src/frontends/qt/Action.h index 411eb72388..53398a0ec6 100644 --- a/src/frontends/qt/Action.h +++ b/src/frontends/qt/Action.h @@ -39,7 +39,7 @@ public: // Takes shared ownership of func. // Use for perf-sensitive code such as populating menus. - Action(std::shared_ptr func, + Action(std::shared_ptr const & func, QIcon const & icon, QString const & text, QString const & tooltip, QObject * parent); diff --git a/src/frontends/qt/TocModel.cpp b/src/frontends/qt/TocModel.cpp index c0c3dce548..ab37c987cd 100644 --- a/src/frontends/qt/TocModel.cpp +++ b/src/frontends/qt/TocModel.cpp @@ -160,7 +160,7 @@ void TocModel::updateItem(DocIterator const & dit) } -void TocModel::reset(shared_ptr toc) +void TocModel::reset(shared_ptr const & toc) { toc_ = toc; if (toc_->empty()) { diff --git a/src/frontends/qt/TocModel.h b/src/frontends/qt/TocModel.h index ee447616d0..b37484fcc6 100644 --- a/src/frontends/qt/TocModel.h +++ b/src/frontends/qt/TocModel.h @@ -39,7 +39,7 @@ public: /// TocModel(QObject * parent); /// - void reset(std::shared_ptr); + void reset(std::shared_ptr const &); /// void reset(); /// diff --git a/src/support/FileMonitor.cpp b/src/support/FileMonitor.cpp index 4a81cc2fc8..3d007ba96c 100644 --- a/src/support/FileMonitor.cpp +++ b/src/support/FileMonitor.cpp @@ -158,7 +158,7 @@ void FileMonitorGuard::notifyChange(QString const & path) } -FileMonitor::FileMonitor(std::shared_ptr monitor) +FileMonitor::FileMonitor(std::shared_ptr const & monitor) : monitor_(monitor) { connectToFileMonitorGuard(); @@ -193,7 +193,7 @@ void FileMonitor::changed(bool const exists) } -ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr monitor, +ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr const & monitor, FileName const & filename, int interval) : FileMonitor(monitor), filename_(filename), interval_(interval), timestamp_(0), checksum_(0), cooldown_(true) diff --git a/src/support/FileMonitor.h b/src/support/FileMonitor.h index 1e43979de4..2b34c7a90f 100644 --- a/src/support/FileMonitor.h +++ b/src/support/FileMonitor.h @@ -128,7 +128,7 @@ class FileMonitor : public QObject Q_OBJECT public: - FileMonitor(std::shared_ptr monitor); + FileMonitor(std::shared_ptr const & monitor); typedef signal sig; typedef sig::slot_type slot; @@ -166,7 +166,7 @@ class ActiveFileMonitor : public FileMonitor { Q_OBJECT public: - ActiveFileMonitor(std::shared_ptr monitor, + ActiveFileMonitor(std::shared_ptr const & monitor, FileName const & filename, int interval); /// call checkModified asynchronously void checkModifiedAsync();