]> git.lyx.org Git - features.git/commitdiff
Backport "Performance" fixes suggested by cppcheck.
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 28 May 2012 20:41:32 +0000 (22:41 +0200)
committerRichard Heck <rgheck@lyx.org>
Mon, 28 May 2012 22:14:15 +0000 (18:14 -0400)
These are completely safe, and it seems best to me to keep trunk
and branch in sync whenever possible, as it makes backporting
easier.

(cherry picked from commit a756403301ff8fb78df4dc1e131e4cd50cd976e1)

Conflicts:

src/BufferParams.cpp
src/tex2lyx/Preamble.cpp
src/tex2lyx/text.cpp

25 files changed:
src/Author.cpp
src/Buffer.cpp
src/BufferParams.cpp
src/CutAndPaste.cpp
src/LayoutModuleList.cpp
src/LyX.cpp
src/Paragraph.cpp
src/Text.cpp
src/TextClass.cpp
src/TextMetrics.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiGraphics.cpp
src/frontends/qt4/LengthCombo.cpp
src/frontends/qt4/LengthCombo.h
src/frontends/qt4/Menus.cpp
src/frontends/qt4/Validator.cpp
src/frontends/qt4/Validator.h
src/graphics/GraphicsLoader.cpp
src/mathed/InsetMathArray.cpp
src/mathed/InsetMathNest.cpp
src/output_latex.cpp
src/output_xhtml.cpp
src/tex2lyx/Preamble.cpp
src/tex2lyx/tex2lyx.cpp
src/tex2lyx/text.cpp

index f1d346ea75619429cebd664ee4ea620097eb4f93..12f7137a5f7587a66ee6732dc5ea9351c52c7078 100644 (file)
@@ -53,7 +53,7 @@ ostream & operator<<(ostream & os, Author const & a)
        // FIXME UNICODE
        os << a.buffer_id_ << " \"" << to_utf8(a.name_)
                        << "\" " << to_utf8(a.email_);
-               
+
        return os;
 }
 
@@ -85,7 +85,7 @@ int AuthorList::record(Author const & a)
        // If we record an author which equals the current
        // author, we copy the buffer_id, so that it will
        // keep the same id in the file.
-       if (authors_.size() > 0 && a == authors_[0])
+       if (!authors_.empty() && a == authors_[0])
                authors_[0].setBufferId(a.bufferId());
 
        Authors::const_iterator it(authors_.begin());
index 7bafb4e51f1ab4ca913f7450d96c2cb1e38c365a..4f7f4418a4f6e06e11cb4837df4e6a466a9b0cfb 100644 (file)
@@ -2778,7 +2778,7 @@ MacroData const * Buffer::Impl::getBufferMacro(docstring const & name,
                                // try previous macro if there is one
                                if (it == nameIt->second.begin())
                                        break;
-                               it--;
+                               --it;
                        }
                }
        }
index 80bda9d3d2279521e09d26804a8bb61fb864c18e..775b8a35a558036d8564a5910a29e06c0d91d664 100644 (file)
@@ -914,7 +914,7 @@ void BufferParams::writeFile(ostream & os) const
                os << "\\begin_removed_modules" << '\n';
                list<string>::const_iterator it = removed_modules_.begin();
                list<string>::const_iterator en = removed_modules_.end();
-               for (; it != en; it++)
+               for (; it != en; ++it)
                        os << *it << '\n';
                os << "\\end_removed_modules" << '\n';
        }
@@ -924,7 +924,7 @@ void BufferParams::writeFile(ostream & os) const
                os << "\\begin_modules" << '\n';
                LayoutModuleList::const_iterator it = layout_modules_.begin();
                LayoutModuleList::const_iterator en = layout_modules_.end();
-               for (; it != en; it++)
+               for (; it != en; ++it)
                        os << *it << '\n';
                os << "\\end_modules" << '\n';
        }
@@ -934,7 +934,7 @@ void BufferParams::writeFile(ostream & os) const
                os << "\\begin_includeonly" << '\n';
                list<string>::const_iterator it = included_children_.begin();
                list<string>::const_iterator en = included_children_.end();
-               for (; it != en; it++)
+               for (; it != en; ++it)
                        os << *it << '\n';
                os << "\\end_includeonly" << '\n';
        }
@@ -2047,8 +2047,8 @@ bool BufferParams::addLayoutModule(string const & modName)
 {
        LayoutModuleList::const_iterator it = layout_modules_.begin();
        LayoutModuleList::const_iterator end = layout_modules_.end();
-       for (; it != end; it++)
-               if (*it == modName) 
+       for (; it != end; ++it)
+               if (*it == modName)
                        return false;
        layout_modules_.push_back(modName);
        return true;
@@ -2373,7 +2373,7 @@ void BufferParams::readRemovedModules(Lexer & lex)
        // start of the read.
        list<string>::const_iterator rit = removed_modules_.begin();
        list<string>::const_iterator const ren = removed_modules_.end();
-       for (; rit != ren; rit++) {
+       for (; rit != ren; ++rit) {
                LayoutModuleList::iterator const mit = layout_modules_.begin();
                LayoutModuleList::iterator const men = layout_modules_.end();
                LayoutModuleList::iterator found = find(mit, men, *rit);
index c2d72af058bff32152c530570da325c07ad4723d..c9fedec2242b861e84a0a270582cfc1d239b4554 100644 (file)
@@ -527,7 +527,7 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
        ParagraphList::iterator it = copy_pars.begin();
        ParagraphList::iterator it_end = copy_pars.end();
 
-       for (; it != it_end; it++) {
+       for (; it != it_end; ++it) {
                // Since we have a copy of the paragraphs, the insets
                // do not have a proper buffer reference. It makes
                // sense to add them temporarily, because the
@@ -552,7 +552,7 @@ void copySelectionHelper(Buffer const & buf, Text const & text,
        // do some final cleanup now, to make sure that the paragraphs
        // are not linked to something else.
        it = copy_pars.begin();
-       for (; it != it_end; it++) {
+       for (; it != it_end; ++it) {
                it->setBuffer(*static_cast<Buffer *>(0));
                it->setInsetOwner(0);
        }
index 83c51fb96764328c07e4d3ded9b97005795c4bd3..a6507212a89c46d5bc17db028a1c15d544487cbe 100644 (file)
@@ -59,7 +59,7 @@ bool LayoutModuleList::moduleCanBeAdded(string const & modName,
        // Is the module already present?
        const_iterator it = begin();
        const_iterator const en = end();
-       for (; it != en; it++)
+       for (; it != en; ++it)
                if (*it == modName) 
                        return false;
 
@@ -131,7 +131,7 @@ void LayoutModuleList::addDefaultModules(LayoutFile const * const lay,
        iterator insertpos = begin();
        int numinserts = 0;
 
-       for (; mit != men; mit++) {
+       for (; mit != men; ++mit) {
                string const & modName = *mit;
                // make sure the user hasn't removed it
                if (find(removedModules.begin(), removedModules.end(), modName) !=
index 5ae488d8f847d10d4d950f2a3e97c23d858eabba..6f3b2c642b4f18ea890463a2d282eefcb092ff77 100644 (file)
@@ -344,7 +344,7 @@ int LyX::exec(int & argc, char * argv[])
                        vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
                        vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
                        DispatchResult dr;
-                       for (; bcit != bcend; bcit++) {
+                       for (; bcit != bcend; ++bcit) {
                                LYXERR(Debug::ACTION, "Buffer::dispatch: cmd: " << *bcit);
                                buf->dispatch(*bcit, dr);
                                final_success |= !dr.error();
@@ -592,7 +592,7 @@ void LyX::execCommands()
 
        vector<string>::const_iterator bcit  = pimpl_->batch_commands.begin();
        vector<string>::const_iterator bcend = pimpl_->batch_commands.end();
-       for (; bcit != bcend; bcit++) {
+       for (; bcit != bcend; ++bcit) {
                LYXERR(Debug::INIT, "About to handle -x '" << *bcit << '\'');
                lyx::dispatch(lyxaction.lookupFunc(*bcit));
        }
index 3054680573c12f3ce701494e4a6db62232dfdc9f..29092b03be835ca674636b13d4f4a063d745ffa1 100644 (file)
@@ -135,7 +135,7 @@ public:
                current_change_number_ = 0;
        }
 
-       void setRange(FontSpan const fp, SpellChecker::Result state)
+       void setRange(FontSpan const fp, SpellChecker::Result state)
        {
                Ranges result;
                RangesIterator et = ranges_.end();
index 1953d163e1a9c4c925a3ef99dc8d38ba1aa6da00..4aba18420744e16e07653e503c5a767731fd721a 100644 (file)
@@ -1668,7 +1668,7 @@ bool Text::dissolveInset(Cursor & cur)
                // change it to the buffer language.
                ParagraphList::iterator it = plist.begin();
                ParagraphList::iterator it_end = plist.end();
-               for (; it != it_end; it++)
+               for (; it != it_end; ++it)
                        it->changeLanguage(b.params(), latex_language, b.language());
 
                pasteParagraphList(cur, plist, b.params().documentClassPtr(),
index c9cbcae5e0578f62b1326b69d3dae93383569c28..7e431b688957b328dc5d07bdf3999eb1bf96015f 100644 (file)
@@ -1318,7 +1318,7 @@ DocumentClass & DocumentClassBundle::makeDocumentClass(
        DocumentClass & doc_class = newClass(baseClass);
        LayoutModuleList::const_iterator it = modlist.begin();
        LayoutModuleList::const_iterator en = modlist.end();
-       for (; it != en; it++) {
+       for (; it != en; ++it) {
                string const modName = *it;
                LyXModule * lm = theModuleList[modName];
                if (!lm) {
index 32ea844f59fcc7ab2286074b977dc82538616e87..10e89046569005f815d10de212a6d7baeb875d11 100644 (file)
@@ -1384,7 +1384,8 @@ pit_type TextMetrics::getPitNearY(int y)
        int yy = -1;
        ParMetricsCache::const_iterator it = par_metrics_.begin();
        ParMetricsCache::const_iterator et = par_metrics_.end();
-       ParMetricsCache::const_iterator last = et; last--;
+       ParMetricsCache::const_iterator last = et;
+       --last;
 
        ParagraphMetrics const & pm = it->second;
 
index 1852ec85df45d5c605ed342118857f7b51664a1c..e2791bc4a99c15ac48c3615ebc599618b0bda71d 100644 (file)
@@ -1956,7 +1956,7 @@ namespace {
        docstring formatStrVec(vector<string> const & v, docstring const & s) 
        {
                //this mess formats the list as "v[0], v[1], ..., [s] v[n]"
-               if (v.size() == 0)
+               if (v.empty())
                        return docstring();
                if (v.size() == 1) 
                        return translateIfPossible(from_utf8(v[0]));
@@ -2012,11 +2012,11 @@ void GuiDocument::modulesToParams(BufferParams & bp)
        list<string>::const_iterator ren = reqmods.end();
 
        // check each of the default modules
-       for (; rit != ren; rit++) {
+       for (; rit != ren; ++rit) {
                list<string>::const_iterator mit = bp.getModules().begin();
                list<string>::const_iterator men = bp.getModules().end();
                bool found = false;
-               for (; mit != men; mit++) {
+               for (; mit != men; ++mit) {
                        if (*rit == *mit) {
                                found = true;
                                break;
index 465ffcea34406d8d5e0804b8962e1fe3838e9526..2ea39a94f6df73e5b0e80861fb98b77e56a57efe 100644 (file)
@@ -574,7 +574,7 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
        set<string>::const_iterator end = grp.end();
        groupCO->blockSignals(true);
        groupCO->clear();
-       for (; it != end; it++)
+       for (; it != end; ++it)
                groupCO->addItem(toqstr(*it), toqstr(*it));
        groupCO->insertItem(0, qt_("None"), QString());
        if (igp.groupId.empty())
index 8e57af1ca6958cbf5ac6a1ac32e440e252bc7016..727eebf16aac4fb69ba877a63ee230d752d4aa7c 100644 (file)
@@ -58,7 +58,7 @@ void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
 }
 
 
-void LengthCombo::setCurrentItem(QString const item)
+void LengthCombo::setCurrentItem(QString const item)
 {
        int num = QComboBox::count();
        for (int i = 0; i < num; i++) {
index f47a178ba89ab1098a3aee91ce0ec330f84e5729..7c7557f9f3a924a12689a8ac7b471b478569ffba 100644 (file)
@@ -31,7 +31,7 @@ public:
        /// set the current item from unit
        virtual void setCurrentItem(lyx::Length::UNIT unit);
        /// set the current item from length string
-       virtual void setCurrentItem(QString const item);
+       virtual void setCurrentItem(QString const item);
        /// set the current item from int
        virtual void setCurrentItem(int item);
        /// get the current item
index c79471d4b9e47dc205bbf763909f2b741bc960f3..af7fe305199dbf9435f695d354202a0a449f39e3 100644 (file)
@@ -747,7 +747,7 @@ void MenuDefinition::expandGraphicsGroups(BufferView const * bv)
        set<string>::const_iterator end = grp.end();
        add(MenuItem(MenuItem::Command, qt_("No Group"), 
                     FuncRequest(LFUN_SET_GRAPHICS_GROUP)));
-       for (; it != end; it++) {
+       for (; it != end; ++it) {
                addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(*it) + '|',
                                FuncRequest(LFUN_SET_GRAPHICS_GROUP, *it)));
        }
index 7f5d5d45e283634838252b710757d72918d08223..13f813e9f39a2f2a52760c58a014875bb4d99a91 100644 (file)
@@ -97,7 +97,7 @@ LengthValidator * unsignedGlueLengthValidator(QLineEdit * ed)
 }
 
 
-LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext)
+LengthAutoValidator::LengthAutoValidator(QWidget * parent, QString const autotext)
        : LengthValidator(parent),
          autotext_(autotext)
 {}
@@ -111,7 +111,7 @@ QValidator::State LengthAutoValidator::validate(QString & qtext, int & dummy) co
 }
 
 
-LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const autotext)
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const autotext)
 {
        LengthAutoValidator * v = new LengthAutoValidator(ed, autotext);
        v->setBottom(Length());
@@ -119,7 +119,7 @@ LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit * ed, QString const
 }
 
 
-DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const autotext)
+DoubleAutoValidator::DoubleAutoValidator(QWidget * parent, QString const autotext)
        : QDoubleValidator(parent),
          autotext_(autotext)
 {}
index e824659323652368a1ac8b87343fe97049529a16..0c4dbde632f0265fb9a1189248d10fd6d3e07d88 100644 (file)
@@ -90,7 +90,7 @@ class LengthAutoValidator : public LengthValidator
        Q_OBJECT
 public:
        /// Define a validator for widget @c parent.
-       LengthAutoValidator(QWidget * parent, QString const autotext);
+       LengthAutoValidator(QWidget * parent, QString const autotext);
 
        /** @returns QValidator::Acceptable if @c data is a GlueLength
                * or is "auto". If not, returns QValidator::Intermediate.
@@ -102,7 +102,7 @@ private:
 };
 
 /// @returns a new @c LengthAutoValidator that does not accept negative lengths.
-LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
+LengthAutoValidator * unsignedLengthAutoValidator(QLineEdit *, QString const autotext);
 
 
 /**
@@ -114,7 +114,7 @@ class DoubleAutoValidator : public QDoubleValidator
 {
        Q_OBJECT
 public:
-       DoubleAutoValidator(QWidget * parent, QString const autotext);
+       DoubleAutoValidator(QWidget * parent, QString const autotext);
        DoubleAutoValidator(double bottom, double top, int decimals,
                QObject * parent);
        QValidator::State validate(QString & input, int & pos) const;
index 82c5b1afda35f702e3c6eb5e1cc7a0a3ebe354f7..36f2839446bbd12f5e0e4cc4b9cf9860f217e438 100644 (file)
@@ -96,7 +96,7 @@ void LoaderQueue::loadNext()
                if (ptr->status() == WaitingToLoad)
                        ptr->startLoading();
        }
-       if (cache_queue_.size()) {
+       if (!cache_queue_.empty()) {
                startLoader();
        } else {
                stopLoader();
index fd7ceebe31c8634089204d583bd4d1ee1bcdd985..821f4605e8f119a5fa74210d319ad9e9d06f4887 100644 (file)
@@ -51,7 +51,7 @@ InsetMathArray::InsetMathArray(Buffer * buf, docstring const & name,
                istringstream ls(line);
                typedef istream_iterator<string> iter;
                vector<string> v = vector<string>(iter(ls), iter());
-               if (v.size())
+               if (!v.empty())
                        dat.push_back(v);
        }
 
index a3d167b66416a7d4de29db5ac73094e3004ddaeb..59358d2a670383ffcebea9b453fea4c1ee5689af 100644 (file)
@@ -2039,7 +2039,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        }
        sort(locals.begin(), locals.end());
 
-       if (globals.size() > 0)
+       if (!globals.empty())
                return;
 
        // fill in global macros
index 0d549f37918add42625230a235dde472d79400ed..103a8bc42a11b88b05907a1053f9a458ad41bea5 100644 (file)
@@ -241,7 +241,6 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
        // This is for debugging purpose at the end.
        pit_type const par_begin = pit;
        for (; pit < runparams.par_end; ++pit) {
-       
                ParagraphList::const_iterator par = paragraphs.constIterator(pit);
 
                // check first if this is an higher depth paragraph.
@@ -278,7 +277,6 @@ void TeXEnvironment(Buffer const & buf, Text const & text,
                        // be two for Standard paragraphs that are depth-increment'ed to be
                        // output correctly. However, tables can also be paragraphs so
                        // don't adjust them.
-                       // 
 
                        // FIXME (Lgb): Will it ever harm to have one '\n' too
                        // many? i.e. that we sometimes will have
@@ -335,7 +333,7 @@ void latexArgInsets(Paragraph const & par, otexstream & os,
                }
        }
 
-       if (!reqargs && ilist.size() == 0)
+       if (!reqargs && ilist.empty())
                return;
 
        bool const have_optional_args = ilist.size() > reqargs;
index 4a587ee5ea9761b107e6064294e3387316606a16..b882c35aacbb297e56e5309bb6241b9044ec6190 100644 (file)
@@ -707,7 +707,7 @@ ParagraphList::const_iterator makeParagraphs(Buffer const & buf,
                //   (ii) We didn't open it and html_in_par is true, 
                //        but we are in the first par, and there is a next par.
                ParagraphList::const_iterator nextpar = par;
-               nextpar++;
+               ++nextpar;
                bool const needclose = 
                        (opened && (!runparams.html_in_par || nextpar != pend))
                        || (!opened && runparams.html_in_par && par == pbegin && nextpar != pend);
index b3202ace136653e12f4db0455e339432a649d7fd..f9e8d5d31a64bd897719271d1063f3ac73051052 100644 (file)
@@ -332,7 +332,7 @@ Author const & Preamble::getAuthor(std::string const & name) const
 {
        Author author(from_utf8(name), empty_docstring());
        for (AuthorList::Authors::const_iterator it = authors_.begin();
-            it != authors_.end(); it++)
+            it != authors_.end(); ++it)
                if (*it == author)
                        return *it;
        static Author const dummy;
@@ -896,7 +896,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
                os << "\\begin_modules\n";
                vector<string>::const_iterator const end = used_modules.end();
                vector<string>::const_iterator it = used_modules.begin();
-               for (; it != end; it++)
+               for (; it != end; ++it)
                        os << *it << '\n';
                os << "\\end_modules\n";
        }
index 5bc77d6d2eeef12399c889ea7707db30280c34e4..5b91e1842d1f30875c6ea6aa429c0e4aa3532b1d 100644 (file)
@@ -273,7 +273,7 @@ bool checkModule(string const & name, bool command)
                DocumentClassBundle & bundle = DocumentClassBundle::get();
                LyXModuleList::const_iterator const end = theModuleList.end();
                LyXModuleList::const_iterator it = theModuleList.begin();
-               for (; it != end; it++) {
+               for (; it != end; ++it) {
                        string const module = it->getID();
                        LayoutModuleList m;
                        // FIXME this excludes all modules that depend on another one
@@ -293,7 +293,7 @@ bool checkModule(string const & name, bool command)
        // needed since it is not unlikely that two different modules define a
        // command with the same name.
        ModuleMap::iterator const end = modules.end();
-       for (ModuleMap::iterator it = modules.begin(); it != end; it++) {
+       for (ModuleMap::iterator it = modules.begin(); it != end; ++it) {
                string const module = it->first;
                if (!used_modules.moduleCanBeAdded(module, &baseClass))
                        continue;
@@ -693,7 +693,7 @@ bool tex2lyx(idocstream & is, ostream & os, string encoding)
        if (!used_modules.empty()) {
                LayoutModuleList::const_iterator const end = used_modules.end();
                LayoutModuleList::const_iterator it = used_modules.begin();
-               for (; it != end; it++)
+               for (; it != end; ++it)
                        preamble.addModule(*it);
        }
        if (!preamble.writeLyXHeader(os, !active_environments.empty())) {
index f79df038f70e0dedc5749103e13126629caf06dc..bdc31b3cf25c485b9402366ab649c551d8fee39c 100644 (file)
@@ -1513,7 +1513,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                if (!preamble.titleLayoutFound())
                        preamble.titleLayoutFound(newlayout->intitle);
                set<string> const & req = newlayout->requires();
-               for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
+               for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
                        preamble.registerAutomaticallyLoadedPackage(*it);
        }
 
@@ -2429,7 +2429,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                                preamble.titleLayoutFound(newlayout->intitle);
                                        set<string> const & req = newlayout->requires();
                                        for (set<string>::const_iterator it = req.begin();
-                                            it != req.end(); it++)
+                                            it != req.end(); ++it)
                                                preamble.registerAutomaticallyLoadedPackage(*it);
                                } else
                                        handle_ert(os,
@@ -2450,7 +2450,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        if (!preamble.titleLayoutFound())
                                preamble.titleLayoutFound(newlayout->intitle);
                        set<string> const & req = newlayout->requires();
-                       for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
+                       for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
                                preamble.registerAutomaticallyLoadedPackage(*it);
                }
 
@@ -2463,7 +2463,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        if (!preamble.titleLayoutFound())
                                preamble.titleLayoutFound(newlayout->intitle);
                        set<string> const & req = newlayout->requires();
-                       for (set<string>::const_iterator it = req.begin(); it != req.end(); it++)
+                       for (set<string>::const_iterator it = req.begin(); it != req.end(); ++it)
                                preamble.registerAutomaticallyLoadedPackage(*it);
                }