From 58ee4c9ec74172b7600f1cc5d2299eba465496d7 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 13 Sep 2024 14:16:21 +0200 Subject: [PATCH] Pass DocumentClassConstPtr arguments by const reference This arguments are shared_ptr objects, so they 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/BufferParams.cpp | 2 +- src/BufferParams.h | 2 +- src/BufferView.cpp | 2 +- src/BufferView.h | 2 +- src/CutAndPaste.cpp | 10 +++++----- src/CutAndPaste.h | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 3906e5f665..cc73b016ca 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -2752,7 +2752,7 @@ DocumentClassConstPtr BufferParams::documentClassPtr() const } -void BufferParams::setDocumentClass(DocumentClassConstPtr tc) +void BufferParams::setDocumentClass(DocumentClassConstPtr const & tc) { // evil, but this function is evil doc_class_ = const_pointer_cast(tc); diff --git a/src/BufferParams.h b/src/BufferParams.h index 52abc6f229..73541c1b08 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -165,7 +165,7 @@ public: /// This bypasses the baseClass and sets the textClass directly. /// Should be called with care and would be better not being here, /// but it seems to be needed by CutAndPaste::putClipboard(). - void setDocumentClass(DocumentClassConstPtr); + void setDocumentClass(DocumentClassConstPtr const &); /// List of modules in use LayoutModuleList const & getModules() const { return layout_modules_; } /// List of default modules the user has removed diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 8f348d4169..41bc6b5c6a 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1162,7 +1162,7 @@ void BufferView::makeDocumentClass() } -void BufferView::updateDocumentClass(DocumentClassConstPtr olddc) +void BufferView::updateDocumentClass(DocumentClassConstPtr const & olddc) { StableDocIterator backcur(d->cursor_); ErrorList & el = buffer_.errorList("Class Switch"); diff --git a/src/BufferView.h b/src/BufferView.h index 24d3ce8950..0f673e38e6 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -456,7 +456,7 @@ private: void updateHoveredInset() const; /// - void updateDocumentClass(DocumentClassConstPtr olddc); + void updateDocumentClass(DocumentClassConstPtr const & olddc); /// int width_; /// diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp index 26cfc9bec8..951c65a87f 100644 --- a/src/CutAndPaste.cpp +++ b/src/CutAndPaste.cpp @@ -600,7 +600,7 @@ PitPosPair eraseSelectionHelper(BufferParams const & params, } -Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPtr docclass) +Buffer * copyToTempBuffer(ParagraphList const & paragraphs, DocumentClassConstPtr const & docclass) { // This used to need to be static to avoid a memory leak. It no longer needs // to be so, but the alternative is to construct a new one of these (with a @@ -828,15 +828,15 @@ bool multipleCellsSelected(CursorData const & cur) } -void switchBetweenClasses(DocumentClassConstPtr oldone, - DocumentClassConstPtr newone, InsetText & in) { +void switchBetweenClasses(DocumentClassConstPtr const & oldone, + DocumentClassConstPtr const & newone, InsetText & in) { ErrorList el = {}; switchBetweenClasses(oldone, newone, in, el); } -void switchBetweenClasses(DocumentClassConstPtr oldone, - DocumentClassConstPtr newone, InsetText & in, ErrorList & errorlist) +void switchBetweenClasses(DocumentClassConstPtr const & oldone, + DocumentClassConstPtr const & newone, InsetText & in, ErrorList & errorlist) { errorlist.clear(); diff --git a/src/CutAndPaste.h b/src/CutAndPaste.h index d7fec67c17..1b1c2f684d 100644 --- a/src/CutAndPaste.h +++ b/src/CutAndPaste.h @@ -138,11 +138,11 @@ void pasteParagraphList(Cursor & cur, ParagraphList const & parlist, * It changes layouts and character styles. Errors are reported * in the passed ErrorList. */ -void switchBetweenClasses(DocumentClassConstPtr oldone, - DocumentClassConstPtr newone, InsetText & in, ErrorList & el); +void switchBetweenClasses(DocumentClassConstPtr const & oldone, + DocumentClassConstPtr const & newone, InsetText & in, ErrorList & el); /// Same but without error reporting. -void switchBetweenClasses(DocumentClassConstPtr oldone, - DocumentClassConstPtr newone, InsetText & in); +void switchBetweenClasses(DocumentClassConstPtr const & oldone, + DocumentClassConstPtr const & newone, InsetText & in); /// Get the current selection as a string. Does not change the selection. /// Does only work if the whole selection is in mathed.