]> git.lyx.org Git - features.git/commitdiff
Follow some of the performance advice from cppcheck
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 13 Sep 2019 14:23:49 +0000 (16:23 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:45 +0000 (15:48 +0200)
Most of that is changing string to string const &.

24 files changed:
src/BiblioInfo.cpp
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/LaTeXFeatures.h
src/LaTeXFonts.cpp
src/LaTeXFonts.h
src/PersonalWordList.h
src/Text.h
src/Text2.cpp
src/TocBackend.cpp
src/TocBackend.h
src/Undo.cpp
src/insets/InsetBibtex.cpp
src/insets/InsetBibtex.h
src/insets/InsetCitation.cpp
src/insets/InsetCitation.h
src/insets/InsetQuotes.cpp
src/insets/InsetQuotes.h
src/lyxfind.cpp
src/lyxfind.h
src/mathed/MathStream.h
src/output_xhtml.h
src/support/limited_stack.h

index c723b9ad398465f483b5a24d399042ffd9a0f61e..746780ac6b42c17afbbf6e57d41d4572ea6c0d86 100644 (file)
@@ -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;
 }
index 18fc0d3a3bb8c545313c7d877d8a95ebc45aea7b..46a9d967f7aa4637d55381e355606bc666f7e272 100644 (file)
@@ -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;
 }
 
index 17a4e6774fe0d8f80971613370134a1275661754..22793ecb997c75b96942363b33794efb3a1d309d 100644 (file)
@@ -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) {
index 778da6b2bd6fec8513d41a9f82382cd59e9d30b4..3a5cd29e3c813c0ed1959ad337ccabc9c3624dc0 100644 (file)
@@ -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
index 235f4df8c4228bf3cfcf7f975ef30c673348398a..8ec5e68cce022b0715dba9efb48f3b2889ee575c 100644 (file)
@@ -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"
index b61c4c7fc509fbadbaf94f235f9fda56bf9104f6..b52a8c06d5e9c94bf96808fc4aa1f0f21f39a974 100644 (file)
@@ -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;
index 7f020acc8e5d8845537b701bc696653c3ff5ec0d..6d08cb9fced8fa8759eadf4d862102fad972822f 100644 (file)
@@ -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);
index d37b7d3137bf2cc230be2df7680a6687bec06bbd..9473c86e340990b8e12edd4e8d018ecf492986aa 100644 (file)
@@ -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
index dc96d839bbd21037712b75b7b56fa8d9c74f2dca..99d83f4a29d25236ba69efcfb8a75faa64d28515 100644 (file)
@@ -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);
 
index f1decc56f4f99b720e49043eaca7a2e25ab0b904..07839a748d016e4d6609a9354bd41e014aecd424 100644 (file)
@@ -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());
 
index 65f96bae892421254ac52607e8668e52ce38a01e..d401e2250936d31f86c4b6c683088f8731676b5a 100644 (file)
@@ -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)
 {
index 0e123ee5f033977201c1f795735eeb7a0a2417b9..6ed3e8ee4fbb65dd240206a0112ef3c1a44fc9b6 100644 (file)
@@ -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;
index a9e0bba8e29a0c4c1ff0019b6fd1996270f85522..28a2e822395abefca4956d3970e079567922f1c1 100644 (file)
@@ -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()
        {
index 91e1e6034d24e9a17448bf667f5c71f9a8f543c6..5ed6ff3d4271336b1fe26ff5083cbf640fba11b3 100644 (file)
@@ -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"));
 
index e6345b856662515c704ac7171d836ac7222a462e..fd447f8cb35a87c1d45947740331542eacb236b2 100644 (file)
@@ -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;
        ///
index 564ea5bb9a5e75b1b72516c4a2aa22bd2a8b5916..1071d5280eb86d0503eb96e9c0ea079db16a2f3d 100644 (file)
@@ -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"));
index d94aefe4e0b3da9b8fc40d81fe506cc30ce3287d..9ac4e0bbd16a07dd26a2ede5a2ff555162ef5379 100644 (file)
@@ -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;
 
index 515d24119d959a93526a64f6a43b6cacfb766181..fca77e5c4dfdce3a6587a8f6367480320d8aefd1 100644 (file)
@@ -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);
index 25b4a8b463c5c19dd375c109b0319a7fb362eacf..362a0e2dfa3254f49b88057a4614d34438d7c7e1 100644 (file)
@@ -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
index 45cbbd96f6c12df151b919a8129a663871e5aa39..4c8386c3bae4a864c9fe9234afd2977314d6ca72 100644 (file)
@@ -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;
index 984473e77db341e414cc6b3f42236c4005d4a25f..bfaae8f43d96d6bfdda818cabdda8637eafd7fdc 100644 (file)
@@ -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
 
index b7e79434af1c02bea66f460abc4b39e215fe7648..777992157744e92f644fca02ece5604a270e467c 100644 (file)
@@ -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_;
index 3c4ad2ae0dd69dc66d23e12f31ae3a2955f21b9d..a9ee0ea090baa8230509aa9cd811a09da9709084 100644 (file)
@@ -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_>
index b17eeae19dbca92efecaedff761a8f40d73d8744..c76497c4479dcabb3368a140d1cdd36cb90c7f79 100644 (file)
@@ -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() {