]> git.lyx.org Git - lyx.git/commitdiff
Fix a bunch of small performance issues spotted by cppcheck
authorJean-Marc <lasgouttes@lyx.org>
Sat, 5 Jul 2014 17:13:10 +0000 (19:13 +0200)
committerJean-Marc <lasgouttes@lyx.org>
Sat, 5 Jul 2014 17:13:10 +0000 (19:13 +0200)
Most of these are about passing const strings parameters as references.

24 files changed:
src/Buffer.cpp
src/Buffer.h
src/BufferParams.cpp
src/BufferParams.h
src/Encoding.cpp
src/Encoding.h
src/LaTeX.cpp
src/Language.h
src/LayoutFile.h
src/PDFOptions.cpp
src/PDFOptions.h
src/frontends/qt4/GuiErrorList.cpp
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiViewSource.cpp
src/graphics/PreviewLoader.cpp
src/insets/InsetExternal.cpp
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h
src/mathed/MathExtern.cpp
src/output_plaintext.cpp
src/output_xhtml.cpp
src/sgml.cpp
src/sgml.h
src/tex2lyx/tex2lyx.cpp

index 0a362c3ef4d857b92f3ee02d34c79960869d586a..6c8194c84f270d843ccba7eec4b2f7e053764918 100644 (file)
@@ -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
 {
index fe0294bf1f608cf0e741102dc5cff54e7aa1ffe1..29992f9ae78af32499bef78fffeabe5584137c75 100644 (file)
@@ -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;
 
index 792f14833fc435b32ae142c6cd6f6747ba1c0cc5..8ae249ea23cea84b05d2be4450c06c31be382a1f 100644 (file)
@@ -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);
 }
index 37063995844ad8d3a94fe8267b0229aa97750a4a..2d7c749eea361f882672d416e75b36560510d120 100644 (file)
@@ -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
index a6f6a60ea3162144c5711fed6c7853658502c9d6..dcf65d7f66ea1f318c23d6e242d8415192750239 100644 (file)
@@ -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;
index ed9c27e465c2b1018f236a9038412c32c1158113..735119795ff00bac69c5b6efee86df72905908f4 100644 (file)
@@ -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_; }
index a6fd6f7983eb5288a5f3b98568520d5e0443c6d3..3436645fec13db6e717d8772bd3b151498d13702 100644 (file)
@@ -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;
index c912326a89793c6a5b4076d300ff0d6dc184a78e..3e54d7bec8db7b0fc236a2a37e705e80b675460c 100644 (file)
@@ -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
index ae2e7cfaaade07b27241e0169244037d6c699451..d602bd99148da6a508fa628caee46713372ece72 100644 (file)
@@ -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_; }
        ///
index 7de277c3212162655a60fcd7b565c43dae64e35f..222be517e836779ad9502d8f9815ef3117d3eaaa 100644 (file)
@@ -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", "");
 }
index cd99b2afc10d4859bcfc30fdfc673fe425389116..756c2f70a4e37482dc8be9c84853b47f17c9c2b1 100644 (file)
@@ -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;
        
        
        /**
index 1ab919880f5e4d386b1654214a4cde5340cff7ad..af83be66789148e72db7739fe82a5d60e623c330 100644 (file)
@@ -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");
index 6dfd337dcdd005f086eb6add84923f46861ae7a6..6584d2e308626a7e412e08fda1659e980759b00d 100644 (file)
@@ -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();
index b2df874437206bde096e139e8559bd5bab06ac1b..284bd64fb463e103b70fdf02a51f31db27adc9d6 100644 (file)
@@ -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,
index a6c2c68284df915bd6731fe20ae6d836e627a9ff..f39bd8ee1d67c88f70612b22efe7cc91110be555 100644 (file)
@@ -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;
index 2e97fc07055bd504c859f044529582c2a28a603d..6417013696a3f043dc12ae4ea3ed3014bb2f0583 100644 (file)
@@ -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();
index 433fe197e7593fc53d25082c82f34f7ef05f9f9e..52c10489f5aec4e0e4218717f2ab62b782549893 100644 (file)
@@ -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
index 8941a831e41f4b6b6d82a5b67354c9a882d89116..52a90f4320c30a5a01ee8b2141f0611af896cfa5 100644 (file)
@@ -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
 
index 236b24ba85f5beb35e565ccfe34ff4934e7e337a..a943dac8028b8140c34e51d325fd2eec2c1472b8 100644 (file)
@@ -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('^');
index 2dfc836f1aceb4906cbc596e532cb63bcbdc65dd..15e700eb8f1cf564d92b0eb273483d2942234a3a 100644 (file)
@@ -217,7 +217,7 @@ void writePlaintextParagraph(Buffer const & buf,
                switch (c) {
                case ' ':
                        os << ' ';
-                       currlinelen++;
+                       ++currlinelen;
                        break;
 
                case '\0':
index d76a35379a160901a4bcd17ab4847dec186dd38b..0a0bfd3cbe328f105941b066eaf53e0552851a7d 100644 (file)
@@ -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;
index 3153ce37200113934c4eaafa5fe9c405d64fc0b3..fdd0ed7270cf32ed4ba5b706eb0622a553837024 100644 (file)
@@ -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,
index 551972d75a2cd1b47e8d6862bf16a5f405dd817b..a46c9fa833a57990dc5910e924d334348ba3b877 100644 (file)
@@ -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,
index 9e3257cf7375c05f67d6243112bb94c7518d9934..89b766cc791f01bdd3cdb345db944b5c513b1af0 100644 (file)
@@ -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();