]> git.lyx.org Git - lyx.git/commitdiff
Pass DocumentClassConstPtr arguments by const reference
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 13 Sep 2024 12:16:21 +0000 (14:16 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 13 Sep 2024 12:16:21 +0000 (14:16 +0200)
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
src/BufferParams.h
src/BufferView.cpp
src/BufferView.h
src/CutAndPaste.cpp
src/CutAndPaste.h

index 3906e5f665b6e6e77791cc9a363b21f64c74e1cb..cc73b016ca9a81dd272ba09d20ac3245074710a3 100644 (file)
@@ -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<DocumentClass>(tc);
index 52abc6f229ef17fd277023d7fd1f2651cfd11fd8..73541c1b0834ebe03c8786a296a9725508325e6c 100644 (file)
@@ -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
index 8f348d416977ea2b64c646b72609a7048acbef5d..41bc6b5c6a71d11c75522bc58daf33c04232f12b 100644 (file)
@@ -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");
index 24d3ce8950848060db030994155ce8fdaa8f7970..0f673e38e6f458875b19c8b49bbb07f5e6929a15 100644 (file)
@@ -456,7 +456,7 @@ private:
        void updateHoveredInset() const;
 
        ///
-       void updateDocumentClass(DocumentClassConstPtr olddc);
+       void updateDocumentClass(DocumentClassConstPtr const & olddc);
        ///
        int width_;
        ///
index 26cfc9bec8ea1ee5fb9340c2394c9e47271b54ad..951c65a87fd79b97e61ee880eeb766bca12e1645 100644 (file)
@@ -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();
 
index d7fec67c176a930b5133531eac25721b75f4134f..1b1c2f684d868dc4a54a677ee8414e6488c39282 100644 (file)
@@ -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.