From: Jean-Marc Lasgouttes Date: Fri, 13 Sep 2019 14:23:49 +0000 (+0200) Subject: Follow some of the performance advice from cppcheck X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2c7e00369014ef8e85f0274b3e659c1d944161e1;p=features.git Follow some of the performance advice from cppcheck Most of that is changing string to string const &. --- diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index c723b9ad39..746780ac6b 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 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 18fc0d3a3b..46a9d967f7 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 17a4e6774f..22793ecb99 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 778da6b2bd..3a5cd29e3c 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 235f4df8c4..8ec5e68cce 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 b61c4c7fc5..b52a8c06d5 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 7f020acc8e..6d08cb9fce 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 d37b7d3137..9473c86e34 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 dc96d839bb..99d83f4a29 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 f1decc56f4..07839a748d 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 65f96bae89..d401e22509 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 0e123ee5f0..6ed3e8ee4f 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 a9e0bba8e2..28a2e82239 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 91e1e6034d..5ed6ff3d42 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 bibfilelist = getVectorFromString(getParam("bibfiles")); diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h index e6345b8566..fd447f8cb3 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 564ea5bb9a..1071d5280e 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -329,7 +329,7 @@ inline docstring wrapCitation(docstring const & key, } // anonymous namespace -vector> InsetCitation::getQualifiedLists(docstring const p) const +vector> InsetCitation::getQualifiedLists(docstring const & p) const { vector ps = getVectorFromString(p, from_ascii("\t")); diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index d94aefe4e0..9ac4e0bbd1 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 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 515d24119d..fca77e5c4d 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 25b4a8b463..362a0e2dfa 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 45cbbd96f6..4c8386c3ba 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(); @@ -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 984473e77d..bfaae8f43d 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 b7e79434af..7779921577 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 3c4ad2ae0d..a9ee0ea090 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() {} /// diff --git a/src/support/limited_stack.h b/src/support/limited_stack.h index b17eeae19d..c76497c447 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() {