commit 3af0bad22a9f6200fcfc09534f5c0925ad63271c Author: Jean-Marc Lasgouttes <lasgout...@lyx.org> Date: Fri Sep 13 14:54:43 2024 +0200
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> toc) +TocBuilder::TocBuilder(shared_ptr<Toc> const & toc) : toc_(toc ? toc : make_shared<Toc>()), 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> toc); + TocBuilder(std::shared_ptr<Toc> 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<FuncRequest const> func, +Action::Action(shared_ptr<FuncRequest const> 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<FuncRequest const> func, + Action(std::shared_ptr<FuncRequest const> 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 const> toc) +void TocModel::reset(shared_ptr<Toc const> 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<Toc const>); + void reset(std::shared_ptr<Toc const> 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<FileMonitorGuard> monitor) +FileMonitor::FileMonitor(std::shared_ptr<FileMonitorGuard> const & monitor) : monitor_(monitor) { connectToFileMonitorGuard(); @@ -193,7 +193,7 @@ void FileMonitor::changed(bool const exists) } -ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> monitor, +ActiveFileMonitor::ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> 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<FileMonitorGuard> monitor); + FileMonitor(std::shared_ptr<FileMonitorGuard> const & monitor); typedef signal<void(bool)> sig; typedef sig::slot_type slot; @@ -166,7 +166,7 @@ class ActiveFileMonitor : public FileMonitor { Q_OBJECT public: - ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> monitor, + ActiveFileMonitor(std::shared_ptr<FileMonitorGuard> const & monitor, FileName const & filename, int interval); /// call checkModified asynchronously void checkModifiedAsync(); -- lyx-cvs mailing list lyx-cvs@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-cvs