commit 93a43742a5f1db8a632233c15e2b8d61b4835f3a Author: Jean-Marc <lasgout...@lyx.org> Date: Sat Jul 5 19:13:10 2014 +0200
Fix a bunch of small performance issues spotted by cppcheck Most of these are about passing const strings parameters as references. diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 0a362c3..6c8194c 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -653,7 +653,7 @@ BufferParams const & Buffer::masterParams() const // Copy child authors to the params. We need those pointers. AuthorList const & child_authors = params().authors(); AuthorList::Authors::const_iterator it = child_authors.begin(); - for (; it != child_authors.end(); it++) + for (; it != child_authors.end(); ++it) mparams.authors().record(*it); return mparams; } @@ -3507,7 +3507,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to) } -void Buffer::getSourceCode(odocstream & os, string const format, +void Buffer::getSourceCode(odocstream & os, string const & format, pit_type par_begin, pit_type par_end, OutputWhat output, bool master) const { diff --git a/src/Buffer.h b/src/Buffer.h index fe0294b..29992f9 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -594,7 +594,7 @@ public: /// get source code (latex/docbook) for some paragraphs, or all paragraphs /// including preamble - void getSourceCode(odocstream & os, std::string const format, + void getSourceCode(odocstream & os, std::string const & format, pit_type par_begin, pit_type par_end, OutputWhat output, bool master) const; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 792f148..8ae249e 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -2280,7 +2280,7 @@ vector<string> BufferParams::backends() const } -OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const +OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const { string const dformat = (format.empty() || format == "default") ? getDefaultOutputFormat() : format; @@ -2362,7 +2362,7 @@ Font const BufferParams::getFont() const } -InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const qs) const +InsetQuotes::QuoteLanguage BufferParams::getQuoteStyle(string const & qs) const { return quoteslangtranslator().find(qs); } diff --git a/src/BufferParams.h b/src/BufferParams.h index 3706399..2d7c749 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -180,7 +180,7 @@ public: std::string getDefaultOutputFormat() const; /// return the output flavor of \p format or the default OutputParams::FLAVOR getOutputFlavor( - std::string const format = std::string()) const; + std::string const & format = std::string()) const; /// bool isExportable(std::string const & format) const; /// @@ -207,7 +207,7 @@ public: Font const getFont() const; /// translate quote style string to enum value - InsetQuotes::QuoteLanguage getQuoteStyle(std::string const qs) const; + InsetQuotes::QuoteLanguage getQuoteStyle(std::string const & qs) const; /* these are for the PaperLayout */ /// the papersize diff --git a/src/Encoding.cpp b/src/Encoding.cpp index a6f6a60..dcf65d7 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -257,9 +257,9 @@ const char * EncodingException::what() const throw() CharInfo::CharInfo( - docstring const textcommand, docstring const mathcommand, - std::string const textpreamble, std::string const mathpreamble, - std::string const tipashortcut, unsigned int flags) + docstring const & textcommand, docstring const & mathcommand, + std::string const & textpreamble, std::string const & mathpreamble, + std::string const & tipashortcut, unsigned int flags) : textcommand_(textcommand), mathcommand_(mathcommand), textpreamble_(textpreamble), mathpreamble_(mathpreamble), tipashortcut_(tipashortcut), flags_(flags) @@ -380,7 +380,7 @@ pair<docstring, bool> Encoding::latexChar(char_type c) const } -pair<docstring, docstring> Encoding::latexString(docstring const input, bool dryrun) const +pair<docstring, docstring> Encoding::latexString(docstring const & input, bool dryrun) const { docstring result; docstring uncodable; diff --git a/src/Encoding.h b/src/Encoding.h index ed9c27e..7351197 100644 --- a/src/Encoding.h +++ b/src/Encoding.h @@ -59,9 +59,9 @@ class CharInfo { public: CharInfo() : flags_(0) {} CharInfo( - docstring const textcommand, docstring const mathcommand, - std::string const textpreamble, std::string const mathpreamble, - std::string const tipashortcut, unsigned int flags); + docstring const & textcommand, docstring const & mathcommand, + std::string const & textpreamble, std::string const & mathpreamble, + std::string const & tipashortcut, unsigned int flags); // we assume that at least one command is nonempty when using unicodesymbols bool isUnicodeSymbol() const { return !textcommand_.empty() || !mathcommand_.empty(); } /// LaTeX command (text mode) for this character @@ -164,7 +164,7 @@ public: * \p dryrun specifies whether the string is used within source * preview (which yields a special warning). */ - std::pair<docstring, docstring> latexString(docstring const input, + std::pair<docstring, docstring> latexString(docstring const & input, bool dryrun = false) const; /// Which LaTeX package handles this encoding? Package package() const { return package_; } diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp index a6fd6f7..3436645 100644 --- a/src/LaTeX.cpp +++ b/src/LaTeX.cpp @@ -1015,7 +1015,7 @@ bool completeFilename(string const & ff, DepTable & head) } -int iterateLine(string const token, regex const reg, string const & closing, +int iterateLine(string const & token, regex const & reg, string const & closing, int fragment_pos, DepTable & head) { smatch what; diff --git a/src/Language.h b/src/Language.h index c912326..3e54d7b 100644 --- a/src/Language.h +++ b/src/Language.h @@ -64,11 +64,11 @@ public: /// language code std::string const & code() const { return code_; } /// set code (needed for rc.spellchecker_alt_lang) - void setCode(std::string const c) { code_ = c; } + void setCode(std::string const & c) { code_ = c; } /// language variety (needed by aspell checker) std::string const & variety() const { return variety_; } /// set variety (needed for rc.spellchecker_alt_lang) - void setVariety(std::string const v) { variety_ = v; } + void setVariety(std::string const & v) { variety_ = v; } /// preamble settings after babel was called std::string const & babel_postsettings() const { return babel_postsettings_; } /// preamble settings before babel is called diff --git a/src/LayoutFile.h b/src/LayoutFile.h index ae2e7cf..d602bd9 100644 --- a/src/LayoutFile.h +++ b/src/LayoutFile.h @@ -34,7 +34,7 @@ public: /// typedef std::string base_type; /// - LayoutFileIndex(base_type t) { data_ = t; } + LayoutFileIndex(base_type const & t) : data_(t) { } /// operator base_type() const { return data_; } /// diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp index 7de277c..222be51 100644 --- a/src/PDFOptions.cpp +++ b/src/PDFOptions.cpp @@ -243,7 +243,7 @@ string PDFOptions::readToken(Lexer &lex, string const & token) // check the string from UI -string PDFOptions::quoted_options_check(string const str) const +string PDFOptions::quoted_options_check(string const & str) const { return subst(str, "\n", ""); } diff --git a/src/PDFOptions.h b/src/PDFOptions.h index cd99b2a..756c2f7 100644 --- a/src/PDFOptions.h +++ b/src/PDFOptions.h @@ -141,7 +141,7 @@ public: * Returns repaired string. For the time being only newlines * are checked. */ - std::string quoted_options_check(std::string const str) const; + std::string quoted_options_check(std::string const & str) const; /** diff --git a/src/frontends/qt4/GuiErrorList.cpp b/src/frontends/qt4/GuiErrorList.cpp index 1ab9198..af83be6 100644 --- a/src/frontends/qt4/GuiErrorList.cpp +++ b/src/frontends/qt4/GuiErrorList.cpp @@ -36,7 +36,7 @@ using namespace lyx::support; namespace { -string const guiErrorType(string const s) +string const guiErrorType(string const & s) { if (s == "docbook") return N_("DocBook"); diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 6dfd337..6584d2e 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -1904,7 +1904,7 @@ PrefFileformats::PrefFileformats(GuiPreferences * form) namespace { -string const l10n_shortcut(string const prettyname, string const shortcut) +string const l10n_shortcut(string const & prettyname, string const & shortcut) { if (shortcut.empty()) return string(); diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp index b2df874..284bd64 100644 --- a/src/frontends/qt4/GuiViewSource.cpp +++ b/src/frontends/qt4/GuiViewSource.cpp @@ -94,7 +94,7 @@ static size_t crcCheck(docstring const & s) \return true if the content has changed since last call. */ static bool getContent(BufferView const * view, Buffer::OutputWhat output, - QString & qstr, string const format, bool force_getcontent, + QString & qstr, string const & format, bool force_getcontent, bool master) { // get the *top* level paragraphs that contain the cursor, diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index a6c2c68..f39bd8e 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -68,7 +68,7 @@ FileName const unique_tex_filename(FileName const & bufferpath) } -lyx::Converter const * setConverter(string const from) +lyx::Converter const * setConverter(string const & from) { typedef vector<string> FmtList; typedef lyx::graphics::Cache GCache; diff --git a/src/insets/InsetExternal.cpp b/src/insets/InsetExternal.cpp index 2e97fc0..6417013 100644 --- a/src/insets/InsetExternal.cpp +++ b/src/insets/InsetExternal.cpp @@ -599,6 +599,7 @@ void InsetExternal::setParams(InsetExternalParams const & p) LASSERT(false, return); break; case PREVIEW_INSTANT: { + //FIXME: why is the value below immediately forgotten? RenderMonitoredPreview * preview_ptr = renderer_->asMonitoredPreview(); renderer_.reset(new RenderMonitoredPreview(this)); preview_ptr = renderer_->asMonitoredPreview(); diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 433fe19..52c1048 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -262,7 +262,7 @@ string const tostr(Tabular::BoxType const & num) // I would have liked a fromstr template a lot better. (Lgb) -bool string2type(string const str, LyXAlignment & num) +bool string2type(string const & str, LyXAlignment & num) { if (str == "none") num = LYX_ALIGN_NONE; @@ -282,7 +282,7 @@ bool string2type(string const str, LyXAlignment & num) } -bool string2type(string const str, Tabular::HAlignment & num) +bool string2type(string const & str, Tabular::HAlignment & num) { if (str == "left") num = Tabular::LYX_LONGTABULAR_ALIGN_LEFT; @@ -296,7 +296,7 @@ bool string2type(string const str, Tabular::HAlignment & num) } -bool string2type(string const str, Tabular::VAlignment & num) +bool string2type(string const & str, Tabular::VAlignment & num) { if (str == "top") num = Tabular::LYX_VALIGN_TOP; @@ -310,7 +310,7 @@ bool string2type(string const str, Tabular::VAlignment & num) } -bool string2type(string const str, Tabular::BoxType & num) +bool string2type(string const & str, Tabular::BoxType & num) { if (str == "none") num = Tabular::BOX_NONE; @@ -324,7 +324,7 @@ bool string2type(string const str, Tabular::BoxType & num) } -bool string2type(string const str, bool & num) +bool string2type(string const & str, bool & num) { if (str == "true") num = true; @@ -534,7 +534,7 @@ DocIterator separatorPos(InsetTableCell * cell, docstring const & align_d) } -InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool & hassep) +InsetTableCell splitCell(InsetTableCell & head, docstring const & align_d, bool & hassep) { InsetTableCell tail = InsetTableCell(head); DocIterator const dit = separatorPos(&head, align_d); @@ -2164,7 +2164,7 @@ bool Tabular::isPartOfMultiRow(row_type row, col_type column) const } -void Tabular::TeXTopHLine(otexstream & os, row_type row, string const lang) const +void Tabular::TeXTopHLine(otexstream & os, row_type row, string const & lang) const { // we only output complete row lines and the 1st row here, the rest // is done in Tabular::TeXBottomHLine(...) @@ -2226,7 +2226,7 @@ void Tabular::TeXTopHLine(otexstream & os, row_type row, string const lang) cons } -void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const lang) const +void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const & lang) const { // we output bottomlines of row r and the toplines of row r+1 // if the latter do not span the whole tabular diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index 8941a83..52a90f4 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -770,9 +770,9 @@ public: /// // helper function for Latex /// - void TeXTopHLine(otexstream &, row_type row, std::string const lang) const; + void TeXTopHLine(otexstream &, row_type row, std::string const & lang) const; /// - void TeXBottomHLine(otexstream &, row_type row, std::string const lang) const; + void TeXBottomHLine(otexstream &, row_type row, std::string const & lang) const; /// void TeXCellPreamble(otexstream &, idx_type cell, bool & ismulticol, bool & ismultirow) const; /// @@ -1029,7 +1029,7 @@ private: std::string const featureAsString(Tabular::Feature feature); /// Split cell on decimal symbol -InsetTableCell splitCell(InsetTableCell & head, docstring const decimal_sym, bool & hassep); +InsetTableCell splitCell(InsetTableCell & head, docstring const & decimal_sym, bool & hassep); } // namespace lyx diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp index 236b24b..a943dac 100644 --- a/src/mathed/MathExtern.cpp +++ b/src/mathed/MathExtern.cpp @@ -1197,7 +1197,7 @@ namespace { istringstream is(out); string line; getline(is, line); - if (line.find("on line") != 0) + if (!prefixIs(line, "on line")) break; // error message not identified getline(is, line); size_t pos = line.find('^'); diff --git a/src/output_plaintext.cpp b/src/output_plaintext.cpp index 2dfc836..15e700e 100644 --- a/src/output_plaintext.cpp +++ b/src/output_plaintext.cpp @@ -217,7 +217,7 @@ void writePlaintextParagraph(Buffer const & buf, switch (c) { case ' ': os << ' '; - currlinelen++; + ++currlinelen; break; case '\0': diff --git a/src/output_xhtml.cpp b/src/output_xhtml.cpp index d76a353..0a0bfd3 100644 --- a/src/output_xhtml.cpp +++ b/src/output_xhtml.cpp @@ -831,7 +831,7 @@ ParagraphList::const_iterator findLastParagraph( ParagraphList::const_iterator findEndOfEnvironment( - ParagraphList::const_iterator const pstart, + ParagraphList::const_iterator const & pstart, ParagraphList::const_iterator const & pend) { ParagraphList::const_iterator p = pstart; diff --git a/src/sgml.cpp b/src/sgml.cpp index 3153ce3..fdd0ed7 100644 --- a/src/sgml.cpp +++ b/src/sgml.cpp @@ -102,7 +102,7 @@ docstring sgml::escapeString(docstring const & raw) } -docstring const sgml::uniqueID(docstring const label) +docstring const sgml::uniqueID(docstring const & label) { // FIXME THREAD // It seems unlikely there could be a problem here, diff --git a/src/sgml.h b/src/sgml.h index 551972d..a46c9fa 100644 --- a/src/sgml.h +++ b/src/sgml.h @@ -37,7 +37,7 @@ docstring cleanID(Buffer const & buf, OutputParams const & runparams, docstring const & orig); /// returns a unique numeric id -docstring const uniqueID(docstring const label); +docstring const uniqueID(docstring const & label); /// Opens tag void openTag(odocstream & os, std::string const & name, diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 9e3257c..89b766c 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -205,7 +205,7 @@ typedef map<string, DocumentClassPtr> ModuleMap; ModuleMap modules; -bool addModule(string const module, LayoutFile const & baseClass, LayoutModuleList & m, vector<string> & visited) +bool addModule(string const & module, LayoutFile const & baseClass, LayoutModuleList & m, vector<string> & visited) { // avoid endless loop for circular dependency vector<string>::const_iterator const vb = visited.begin();