Le 13 septembre 2019 16:15:52 GMT+02:00, Jean-Marc Lasgouttes 
<lasgout...@lyx.org> a écrit :
>commit 714113655ad434f9a73d0101038568d59311af72
>Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
>Date:   Fri Sep 13 16:23:49 2019 +0200
>
>    Follow some of the performance advice from cppcheck
>    
>    Most of that is changing string to string const &.

There are 3 warnings that I did not fix in BiblioInfo.cpp about passing a 
BiblioInfoList array by value.

I figured I can ask first : is there a reason for copying the array or is it an 
oversight?

JMarc

>---
> src/BiblioInfo.cpp           |    4 ++--
> src/Buffer.cpp               |    2 +-
> src/BufferParams.cpp         |    2 +-
> src/BufferParams.h           |    2 +-
> src/LaTeXFeatures.h          |    2 +-
> src/LaTeXFonts.cpp           |    4 ++--
> src/LaTeXFonts.h             |    4 ++--
> src/PersonalWordList.h       |    2 +-
> src/Text.h                   |    2 +-
> src/Text2.cpp                |    2 +-
> src/TocBackend.cpp           |    2 +-
> src/TocBackend.h             |    4 ++--
> src/Undo.cpp                 |   24 +++++++++---------------
> src/insets/InsetBibtex.cpp   |    2 +-
> src/insets/InsetBibtex.h     |    2 +-
> src/insets/InsetCitation.cpp |    2 +-
> src/insets/InsetCitation.h   |    2 +-
> src/insets/InsetQuotes.cpp   |    4 ++--
> src/insets/InsetQuotes.h     |    2 +-
> src/lyxfind.cpp              |   11 ++++++-----
> src/lyxfind.h                |    5 +----
> src/mathed/MathStream.h      |    2 +-
> src/output_xhtml.h           |    2 +-
> src/support/limited_stack.h  |    4 +---
> 24 files changed, 42 insertions(+), 52 deletions(-)
>
>diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
>index c723b9a..746780a 100644
>--- a/src/BiblioInfo.cpp
>+++ b/src/BiblioInfo.cpp
>@@ -223,7 +223,7 @@ name_parts nameParts(docstring const & iname)
> }
> 
> 
>-docstring constructName(docstring const & name, string const scheme)
>+docstring constructName(docstring const & name, string const & scheme)
> {
>       // re-constructs a name from name parts according
>       // to a given scheme
>@@ -313,7 +313,7 @@ vector<docstring> const getAuthors(docstring const
>& author)
> }
> 
> 
>-bool multipleAuthors(docstring const author)
>+bool multipleAuthors(docstring const & author)
> {
>       return getAuthors(author).size() > 1;
> }
>diff --git a/src/Buffer.cpp b/src/Buffer.cpp
>index 18fc0d3..46a9d96 100644
>--- a/src/Buffer.cpp
>+++ b/src/Buffer.cpp
>@@ -3583,7 +3583,7 @@ typename M::const_iterator greatest_below(M & m,
>typename M::key_type const & x)
>       if (it == m.begin())
>               return m.end();
> 
>-      it--;
>+      --it;
>       return it;
> }
> 
>diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
>index 17a4e67..22793ec 100644
>--- a/src/BufferParams.cpp
>+++ b/src/BufferParams.cpp
>@@ -2935,7 +2935,7 @@ void BufferParams::readIncludeonly(Lexer & lex)
> }
> 
> 
>-string BufferParams::paperSizeName(PapersizePurpose purpose, string
>const psize) const
>+string BufferParams::paperSizeName(PapersizePurpose purpose, string
>const & psize) const
> {
>       PAPER_SIZE ppsize = psize.empty() ? papersize :
>papersizetranslator().find(psize);
>       switch (ppsize) {
>diff --git a/src/BufferParams.h b/src/BufferParams.h
>index 778da6b..3a5cd29 100644
>--- a/src/BufferParams.h
>+++ b/src/BufferParams.h
>@@ -467,7 +467,7 @@ public:
>       };
>       ///
>       std::string paperSizeName(PapersizePurpose purpose,
>-                                std::string const psize = std::string()) 
>const;
>+                                std::string const & psize = std::string()) 
>const;
>       /// set up if and how babel is called
>       std::string babelCall(std::string const & lang_opts, bool const
>langoptions) const;
>       /// return supported drivers for specific packages
>diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
>index 235f4df..8ec5e68 100644
>--- a/src/LaTeXFeatures.h
>+++ b/src/LaTeXFeatures.h
>@@ -169,7 +169,7 @@ public:
>       /// set savenote environment (footnote package)
>       std::string saveNoteEnv() const { return savenote_env_; }
>       /// return savenote environment
>-      void saveNoteEnv(std::string const s) { savenote_env_ = s; }
>+      void saveNoteEnv(std::string const & s) { savenote_env_ = s; }
>       /// Runparams that will be used for exporting this file.
>       OutputParams const & runparams() const { return runparams_; }
>       /// Resolve alternatives like "esint|amsmath|wasysym"
>diff --git a/src/LaTeXFonts.cpp b/src/LaTeXFonts.cpp
>index b61c4c7..b52a8c0 100644
>--- a/src/LaTeXFonts.cpp
>+++ b/src/LaTeXFonts.cpp
>@@ -243,7 +243,7 @@ string const LaTeXFont::getAvailablePackage(bool
>dryrun)
> 
> 
>string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool
>sc, bool osf,
>-                                        int scale, string const extraopts, 
>bool nomath)
>+                                        int scale, string const & extraopts, 
>bool nomath)
> {
>       ostringstream os;
>       bool const needosfopt = (osf != osfdefault_);
>@@ -290,7 +290,7 @@ string const LaTeXFont::getPackageOptions(bool ot1,
>bool complete, bool sc, bool
> 
> 
>string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool
>complete, bool sc,
>-                                   bool osf, bool nomath, string const 
>extraopts,
>+                                   bool osf, bool nomath, string const & 
>extraopts,
>                                    int const & scale)
> {
>       ostringstream os;
>diff --git a/src/LaTeXFonts.h b/src/LaTeXFonts.h
>index 7f020ac..6d08cb9 100644
>--- a/src/LaTeXFonts.h
>+++ b/src/LaTeXFonts.h
>@@ -84,7 +84,7 @@ public:
>       /// Return the LaTeX Code
>       std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
>                                      bool sc, bool osf, bool nomath,
>-                                     std::string const extraopts = 
>std::string(),
>+                                     std::string const & extraopts = 
>std::string(),
>                                      int const & scale = 100);
>       /// Return the actually used font
>       docstring const getUsedFont(bool ot1, bool complete, bool nomath);
>@@ -103,7 +103,7 @@ private:
>                                           bool sc,
>                                           bool osf,
>                                           int scale,
>-                                          std::string const extraopts,
>+                                          std::string const & extraopts,
>                                           bool nomath);
>       /// Return an alternative font
>       LaTeXFont altFont(docstring const & name);
>diff --git a/src/PersonalWordList.h b/src/PersonalWordList.h
>index d37b7d3..9473c86 100644
>--- a/src/PersonalWordList.h
>+++ b/src/PersonalWordList.h
>@@ -24,7 +24,7 @@ namespace lyx {
> class PersonalWordList {
> public:
>       /// the word list has an associated language
>-      PersonalWordList(std::string lang) : lang_(lang), dirty_(false) {}
>+      PersonalWordList(std::string & lang) : lang_(lang), dirty_(false) {}
>       /// the location of the file to hold to word list
>       lyx::support::FileName dictfile() const;
>       /// (re)load the word list from file
>diff --git a/src/Text.h b/src/Text.h
>index dc96d83..99d83f4 100644
>--- a/src/Text.h
>+++ b/src/Text.h
>@@ -260,7 +260,7 @@ public:
>        settings are given to the new one.
>        This function will handle a multi-paragraph selection.
>        */
>-      void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
>+      void setParagraphs(Cursor & cur, docstring const & arg, bool modify =
>false);
>       /// Sets parameters for current or selected paragraphs
>       void setParagraphs(Cursor & cur, ParagraphParameters const & p);
> 
>diff --git a/src/Text2.cpp b/src/Text2.cpp
>index f1decc5..07839a7 100644
>--- a/src/Text2.cpp
>+++ b/src/Text2.cpp
>@@ -483,7 +483,7 @@ void Text::setLabelWidthStringToSequence(Cursor
>const & cur,
> }
> 
> 
>-void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
>+void Text::setParagraphs(Cursor & cur, docstring const & arg, bool
>merge)
> {
>       LBUFERR(cur.text());
> 
>diff --git a/src/TocBackend.cpp b/src/TocBackend.cpp
>index 65f96ba..d401e22 100644
>--- a/src/TocBackend.cpp
>+++ b/src/TocBackend.cpp
>@@ -43,7 +43,7 @@ namespace lyx {
>///////////////////////////////////////////////////////////////////////////
> 
> TocItem::TocItem(DocIterator const & dit, int d, docstring const & s,
>-                 bool output_active, FuncRequest action)
>+                 bool output_active, FuncRequest const & action)
>       : dit_(dit), depth_(d), str_(s), output_(output_active),
>         action_(action)
> {
>diff --git a/src/TocBackend.h b/src/TocBackend.h
>index 0e123ee..6ed3e8e 100644
>--- a/src/TocBackend.h
>+++ b/src/TocBackend.h
>@@ -61,7 +61,7 @@ public:
>               int depth,
>               docstring const & s,
>               bool output_active,
>-              FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
>+              FuncRequest const & action = FuncRequest(LFUN_UNKNOWN_ACTION)
>               );
>       ///
>       DocIterator const & dit() const { return dit_; }
>@@ -74,7 +74,7 @@ public:
>       ///
>       bool isOutput() const { return output_; }
>       ///
>-      void setAction(FuncRequest a) { action_ = a; }
>+      void setAction(FuncRequest const & a) { action_ = a; }
> 
>       /// custom action, or the default one (paragraph-goto) if not
>customised
>       FuncRequest action() const;
>diff --git a/src/Undo.cpp b/src/Undo.cpp
>index a9e0bba..28a2e82 100644
>--- a/src/Undo.cpp
>+++ b/src/Undo.cpp
>@@ -90,21 +90,15 @@ struct UndoElement
>       {
>       }
>       ///
>-      UndoElement(UndoElement const & ue) : time(current_time())
>-      {
>-              kind = ue.kind;
>-              cur_before = ue.cur_before;
>-              cur_after = ue.cur_after;
>-              cell = ue.cell;
>-              from = ue.from;
>-              end = ue.end;
>-              pars = ue.pars;
>-              array = ue.array;
>-              bparams = ue.bparams
>-                      ? new BufferParams(*ue.bparams) : 0;
>-              lyx_clean = ue.lyx_clean;
>-              group_id = ue.group_id;
>-      }
>+      UndoElement(UndoElement const & ue) :
>+              kind(ue.kind),
>+              cur_before(ue.cur_before), cur_after(ue.cur_after),
>+              cell(ue.cell), from(ue.from), end(ue.end),
>+              pars(ue.pars), array(ue.array),
>+              bparams(ue.bparams ? new BufferParams(*ue.bparams) : 0),
>+              lyx_clean(ue.lyx_clean), group_id(ue.group_id),
>+              time(current_time())
>+              {}
>       ///
>       ~UndoElement()
>       {
>diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
>index 91e1e60..5ed6ff3 100644
>--- a/src/insets/InsetBibtex.cpp
>+++ b/src/insets/InsetBibtex.cpp
>@@ -132,7 +132,7 @@ bool InsetBibtex::getStatus(Cursor & cur,
>FuncRequest const & cmd,
> }
> 
> 
>-void InsetBibtex::editDatabases(docstring const db) const
>+void InsetBibtex::editDatabases(docstring const & db) const
> {
>       vector<docstring> bibfilelist =
>getVectorFromString(getParam("bibfiles"));
> 
>diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h
>index e6345b8..fd447f8 100644
>--- a/src/insets/InsetBibtex.h
>+++ b/src/insets/InsetBibtex.h
>@@ -82,7 +82,7 @@ public:
> 
> private:
>       ///
>-      void editDatabases(docstring const db = docstring()) const;
>+      void editDatabases(docstring const & db = docstring()) const;
>       ///
>       void parseBibTeXFiles(support::FileNameList &) const;
>       ///
>diff --git a/src/insets/InsetCitation.cpp
>b/src/insets/InsetCitation.cpp
>index 564ea5b..1071d52 100644
>--- a/src/insets/InsetCitation.cpp
>+++ b/src/insets/InsetCitation.cpp
>@@ -329,7 +329,7 @@ inline docstring wrapCitation(docstring const &
>key,
> } // anonymous namespace
> 
> 
>-vector<pair<docstring, docstring>>
>InsetCitation::getQualifiedLists(docstring const p) const
>+vector<pair<docstring, docstring>>
>InsetCitation::getQualifiedLists(docstring const & p) const
> {
>       vector<docstring> ps =
>               getVectorFromString(p, from_ascii("\t"));
>diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h
>index d94aefe..9ac4e0b 100644
>--- a/src/insets/InsetCitation.h
>+++ b/src/insets/InsetCitation.h
>@@ -91,7 +91,7 @@ public:
>       CitationStyle getCitationStyle(BufferParams const & bp, std::string
>const & input,
>                                      std::vector<CitationStyle> const & 
> valid_styles) const;
>       ///
>-      QualifiedList getQualifiedLists(docstring const p) const;
>+      QualifiedList getQualifiedLists(docstring const & p) const;
>       ///
>       static bool last_literal;
> 
>diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp
>index 515d241..fca77e5 100644
>--- a/src/insets/InsetQuotes.cpp
>+++ b/src/insets/InsetQuotes.cpp
>@@ -588,9 +588,9 @@ docstring const
>InsetQuotesParams::getGuiLabel(QuoteStyle const & qs, bool langd
> }
> 
> 
>-docstring const InsetQuotesParams::getShortGuiLabel(docstring const
>string)
>+docstring const InsetQuotesParams::getShortGuiLabel(docstring const &
>str)
> {
>-      std::string const s = to_ascii(string);
>+      string const s = to_ascii(str);
>       QuoteStyle const style = getQuoteStyle(s);
>       QuoteSide const side = getQuoteSide(s);
>       QuoteLevel const level = getQuoteLevel(s);
>diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h
>index 25b4a8b..362a0e2 100644
>--- a/src/insets/InsetQuotes.h
>+++ b/src/insets/InsetQuotes.h
>@@ -86,7 +86,7 @@ public:
>       docstring const getGuiLabel(QuoteStyle const & qs,
>                                   bool langdef = false);
>       /// Returns a descriptive label of a given char
>-      docstring const getShortGuiLabel(docstring const string);
>+      docstring const getShortGuiLabel(docstring const & str);
>       ///
>       int stylescount() const;
>       /// Returns the matching style shortcut char
>diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
>index 45cbbd9..4c8386c 100644
>--- a/src/lyxfind.cpp
>+++ b/src/lyxfind.cpp
>@@ -93,7 +93,7 @@ class IgnoreFormats {
>       ///
>       bool getLanguage() { return ignoreLanguage_; };
>       ///
>-      void setIgnoreFormat(string type, bool value);
>+      void setIgnoreFormat(string const & type, bool value);
> 
> private:
>       ///
>@@ -119,7 +119,7 @@ private:
> };
> 
> 
>-void IgnoreFormats::setIgnoreFormat(string type, bool value)
>+void IgnoreFormats::setIgnoreFormat(string const & type, bool value)
> {
>       if (type == "color") {
>               ignoreColor_ = value;
>@@ -160,7 +160,7 @@ void IgnoreFormats::setIgnoreFormat(string type,
>bool value)
> IgnoreFormats ignoreFormats;
> 
> 
>-void setIgnoreFormat(string type, bool value)
>+void setIgnoreFormat(string const & type, bool value)
> {
>   ignoreFormats.setIgnoreFormat(type, value);
> }
>@@ -1478,7 +1478,8 @@ class LatexInfo {
>   void removeHead(KeyInfo&, int count=0);
> 
>  public:
>- LatexInfo(string par, bool isPatternString) : entidx_(-1),
>interval_(isPatternString, par)
>+ LatexInfo(string const & par, bool isPatternString)
>+       : entidx_(-1), interval_(isPatternString, par)
>   {
>     buildKeys(isPatternString);
>     entries_ = vector<KeyInfo>();
>@@ -1588,7 +1589,7 @@ class MathInfo {
>   MathInfo() {
>     actualIdx_ = 0;
>   }
>-  void insert(string wait, size_t start, size_t end) {
>+  void insert(string const & wait, size_t start, size_t end) {
>     MathEntry m = MathEntry();
>     m.wait = wait;
>     m.mathStart = start;
>diff --git a/src/lyxfind.h b/src/lyxfind.h
>index 984473e..bfaae8f 100644
>--- a/src/lyxfind.h
>+++ b/src/lyxfind.h
>@@ -120,7 +120,7 @@ public:
> };
> 
> /// Set the formats that should be ignored
>-void setIgnoreFormat(std::string type, bool value);
>+void setIgnoreFormat(std::string const & type, bool value);
> 
> /// Write a FindAdvOptions instance to a stringstream
>std::ostringstream & operator<<(std::ostringstream & os,
>lyx::FindAndReplaceOptions const & opt);
>@@ -143,9 +143,6 @@ docstring stringifyFromForSearch(
>       DocIterator const & cur,
>       int len = -1);
> 
>-/** Set format type to be ignore by search
>- **/
>-void setIgnoreFormat(std::string type, bool value);
> 
> } // namespace lyx
> 
>diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
>index b7e7943..7779921 100644
>--- a/src/mathed/MathStream.h
>+++ b/src/mathed/MathStream.h
>@@ -296,7 +296,7 @@ private:
> class MTag {
> public:
>       ///
>-      MTag(char const * const tag, std::string attr = "")
>+      MTag(char const * const tag, std::string const & attr =
>std::string())
>               : tag_(tag), attr_(attr) {}
>       ///
>       char const * const tag_;
>diff --git a/src/output_xhtml.h b/src/output_xhtml.h
>index 3c4ad2a..a9ee0ea 100644
>--- a/src/output_xhtml.h
>+++ b/src/output_xhtml.h
>@@ -75,7 +75,7 @@ struct StartTag
> struct EndTag
> {
>       ///
>-      explicit EndTag(std::string tag) : tag_(tag) {}
>+      explicit EndTag(std::string const & tag) : tag_(tag) {}
>       ///
>       virtual ~EndTag() {}
>       /// </tag_>
>diff --git a/src/support/limited_stack.h b/src/support/limited_stack.h
>index b17eeae..c76497c 100644
>--- a/src/support/limited_stack.h
>+++ b/src/support/limited_stack.h
>@@ -32,9 +32,7 @@ public:
>       typedef typename container_type::const_iterator const_iterator;
> 
>       /// limit is the maximum size of the stack
>-      limited_stack(size_type limit = 100) {
>-              limit_ = limit;
>-      }
>+      limited_stack(size_type limit = 100) : limit_(limit) {}
> 
>       /// Return the top element.
>       value_type & top() {

Reply via email to