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.
This commit is contained in:
Jean-Marc Lasgouttes 2024-09-13 14:54:43 +02:00
parent 58ee4c9ec7
commit 3af0bad22a
8 changed files with 10 additions and 10 deletions

View File

@ -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_()
{

View File

@ -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,

View File

@ -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)

View File

@ -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);

View File

@ -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()) {

View File

@ -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();
///

View File

@ -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)

View File

@ -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();