]> git.lyx.org Git - features.git/commitdiff
There was a bit too much copying of dociterators gpoing on leading to an
authorAndré Pönitz <poenitz@gmx.net>
Sat, 12 Jan 2008 21:38:51 +0000 (21:38 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sat, 12 Jan 2008 21:38:51 +0000 (21:38 +0000)
avoidable ~5% overhead when loading the UserGuide. This is an attempt on
rectifying the situation.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22532 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/Cursor.cpp
src/Cursor.h
src/ParIterator.cpp
src/ParIterator.h
src/Paragraph.cpp
src/Text.cpp
src/TextMetrics.cpp
src/buffer_funcs.cpp
src/buffer_funcs.h

index 7cef49baef5961c5cc80d1c6a1f651008de633d9..2c44c7f3c3e415529b220b461fe17418e914823a 100644 (file)
@@ -948,7 +948,6 @@ bool Buffer::write(ostream & ofs) const
            << "\\lyxformat " << LYX_FORMAT << "\n"
            << "\\begin_document\n";
 
-
        /// For each author, set 'used' to true if there is a change
        /// by this author in the document; otherwise set it to 'false'.
        AuthorList::Authors::const_iterator a_it = params().authors().begin();
@@ -956,8 +955,8 @@ bool Buffer::write(ostream & ofs) const
        for (; a_it != a_end; ++a_it)
                a_it->second.setUsed(false);
 
-       ParIterator const end = par_iterator_end();
-       ParIterator it = par_iterator_begin();
+       ParIterator const end = const_cast<Buffer *>(this)->par_iterator_end();
+       ParIterator it = const_cast<Buffer *>(this)->par_iterator_begin();
        for ( ; it != end; ++it)
                it->checkAuthors(params().authors());
 
@@ -1487,7 +1486,7 @@ bool Buffer::isMultiLingual() const
 }
 
 
-ParIterator Buffer::getParFromID(int const id) const
+ParConstIterator Buffer::getParFromID(int const id) const
 {
        ParConstIterator it = par_iterator_begin();
        ParConstIterator const end = par_iterator_end();
@@ -1506,6 +1505,25 @@ ParIterator Buffer::getParFromID(int const id) const
 }
 
 
+ParIterator Buffer::getParFromID(int const id)
+{
+       ParIterator it = par_iterator_begin();
+       ParIterator const end = par_iterator_end();
+
+       if (id < 0) {
+               // John says this is called with id == -1 from undo
+               lyxerr << "getParFromID(), id: " << id << endl;
+               return end;
+       }
+
+       for (; it != end; ++it)
+               if (it->id() == id)
+                       return it;
+
+       return end;
+}
+
+
 bool Buffer::hasParWithID(int const id) const
 {
        ParConstIterator const it = getParFromID(id);
@@ -1989,9 +2007,10 @@ void Buffer::updateMacros() const
 
 void Buffer::updateMacroInstances() const
 {
-       LYXERR(Debug::MACROS, "updateMacroInstances for " << d->filename.onlyFileName());
-       ParIterator it = par_iterator_begin();
-       ParIterator end = par_iterator_end();
+       LYXERR(Debug::MACROS, "updateMacroInstances for "
+               << d->filename.onlyFileName());
+       ParConstIterator it = par_iterator_begin();
+       ParConstIterator end = par_iterator_end();
        for (; it != end; it.forwardPos()) {
                // look for MathData cells in InsetMathNest insets
                Inset * inset = it.nextInset();
index 61f6c4ae09cf451ac91fec342a4deb1b03cf6613..be21e3cec7f4608f2861e8fc61cce7787fdbccb9 100644 (file)
@@ -143,7 +143,9 @@ public:
                pit_type &, pos_type &,
                Font const &, docstring const &, bool);
        ///
-       ParIterator getParFromID(int id) const;
+       ParIterator getParFromID(int id);
+       ///
+       ParConstIterator getParFromID(int id) const;
        /// do we have a paragraph with this id?
        bool hasParWithID(int id) const;
 
index eb23d79533094ea87ecf8ad64ba81515eabe79dc..2b301257f69a31d0ec30a5902456573458423473 100644 (file)
 #include <config.h>
 
 #include "Bidi.h"
-#include "BufferView.h"
 #include "Buffer.h"
-#include "Cursor.h"
+#include "BufferView.h"
 #include "CoordCache.h"
+#include "Cursor.h"
 #include "CutAndPaste.h"
 #include "DispatchResult.h"
 #include "Encoding.h"
+#include "Font.h"
 #include "FuncRequest.h"
 #include "Language.h"
 #include "lfuns.h"
-#include "Font.h"
 #include "LyXFunc.h" // only for setMessage()
 #include "LyXRC.h"
-#include "Row.h"
-#include "Text.h"
-#include "Paragraph.h"
 #include "paragraph_funcs.h"
+#include "Paragraph.h"
 #include "ParIterator.h"
+#include "Row.h"
+#include "Text.h"
 #include "TextMetrics.h"
+#include "TocBackend.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -1639,4 +1640,14 @@ void Cursor::recordUndoSelection()
 }
 
 
+void Cursor::checkBufferStructure()
+{
+       if (paragraph().layout()->toclevel == Layout::NOT_IN_TOC)
+               return;
+       Buffer const * master = buffer().masterBuffer();
+       master->tocBackend().updateItem(ParConstIterator(*this));
+       master->structureChanged();
+}
+
+
 } // namespace lyx
index 0d49502ef1903ece576a8f1ea496cb439ada44eb..7991d0890ad3d226199e47ae02c3afe4caa1170e 100644 (file)
@@ -217,6 +217,9 @@ public:
        /// Convenience: prepare undo for the selected paragraphs
        void recordUndoSelection();
 
+       ///
+       void checkBufferStructure();
+
 public:
        ///
        BufferView * bv_;
index 867e86ca544d4c78a7e0d93e276ceac69e8dbb75..5c0660d452103a6a83f98c49e7628fb77e992e45 100644 (file)
@@ -104,18 +104,6 @@ ParagraphList & ParIterator::plist() const
 }
 
 
-bool operator==(ParIterator const & iter1, ParIterator const & iter2)
-{
-       return DocIterator(iter1) == DocIterator(iter2);
-}
-
-
-bool operator!=(ParIterator const & iter1, ParIterator const & iter2)
-{
-       return !(iter1 == iter2);
-}
-
-
 DocIterator makeDocIterator(ParIterator const & par, pos_type pos)
 {
        DocIterator dit(par);
@@ -164,9 +152,10 @@ ParagraphList const & ParConstIterator::plist() const
        return text()->paragraphs();
 }
 
-
+#if 0
 bool operator==(ParConstIterator const & iter1, ParConstIterator const & iter2)
 {
+       // FIXME: this makes two full copies!
        return DocIterator(iter1) == DocIterator(iter2);
 }
 
@@ -175,6 +164,7 @@ bool operator!=(ParConstIterator const & iter1, ParConstIterator const & iter2)
 {
        return !(iter1 == iter2);
 }
+#endif
 
 
 // FIXME: const correctness!
index af41cc0744ed91b69f4af2a471ee0de734498423..71e5417ddc8a6a1e2006ecdf606065821c7c00d7 100644 (file)
@@ -45,7 +45,7 @@ public:
        ///
        ParIterator(ParIterator const &);
        ///
-       ParIterator(DocIterator const &);
+       explicit ParIterator(DocIterator const &);
 
        /// This really should be implemented...
        //ParIterator & operator=(ParIterator const &);
@@ -79,15 +79,15 @@ ParIterator par_iterator_end(Inset & inset);
 
 
 ///
-bool operator==(ParIterator const & iter1, ParIterator const & iter2);
+//bool operator==(ParIterator const & it1, ParIterator const & it2);
 
-// FIXME: Unfortunately operator!=(ParIterator &, ParIterator &) is implemented with
-// operator!=(DocIterator &, DocIterator &) that gives false if the positions
-// are different, even if the pars are the same. So ultimately it's a bug in
-// operator!=(ParIterator &, ParIterator &) I'd say (nevertheless, I would be
-// reluctant to change it, because I fear that some part of the code could rely on
-// this "bug". --Alfredo
-bool operator!=(ParIterator const & iter1, ParIterator const & iter2);
+// FIXME: Unfortunately operator!=(ParIterator &, ParIterator &) is
+// implemented with operator!=(DocIterator &, DocIterator &) that gives
+// false if the positions are different, even if the pars are the same.
+// So ultimately it's a bug in operator!=(ParIterator &, ParIterator &)
+// I'd say (nevertheless, I would be reluctant to change it, because I
+// fear that some part of the code could rely on this "bug". --Alfredo
+//bool operator!=(ParIterator const & it1, ParIterator const & it2);
 
 
 class ParConstIterator : public std::iterator<std::forward_iterator_tag,
@@ -96,11 +96,11 @@ class ParConstIterator : public std::iterator<std::forward_iterator_tag,
 {
 public:
        ///
-       ParConstIterator(): DocIterator() {}
+       ParConstIterator() : DocIterator() {}
        ///
        ParConstIterator(ParConstIterator const &);
        ///
-       ParConstIterator(DocIterator const &);
+       explicit ParConstIterator(DocIterator const &);
        ///
 
        ParConstIterator & operator++();
@@ -114,11 +114,9 @@ public:
        ParagraphList const & plist() const;
 };
 
-bool operator==(ParConstIterator const & iter1,
-               ParConstIterator const & iter2);
+//bool operator==(ParConstIterator const & it1, ParConstIterator const & it2);
 
-bool operator!=(ParConstIterator const & iter1,
-               ParConstIterator const & iter2);
+//bool operator!=(ParConstIterator const & it1, ParConstIterator const & it2);
 
 
 ParConstIterator par_const_iterator_begin(Inset const & inset);
index e1b4cf1596a98f5a05fc266cdf9c85b3eed6852d..aeece98bddc6e20b6b0b50b6757fdd69640a45a8 100644 (file)
@@ -250,15 +250,13 @@ bool Paragraph::isChanged(pos_type start, pos_type end) const
 }
 
 
-bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const {
+bool Paragraph::isMergedOnEndOfParDeletion(bool trackChanges) const
+{
        // keep the logic here in sync with the logic of eraseChars()
-
-       if (!trackChanges) {
+       if (!trackChanges)
                return true;
-       }
-
-       Change change = d->changes_.lookup(size());
 
+       Change const change = d->changes_.lookup(size());
        return change.type == Change::INSERTED && change.author == 0;
 }
 
@@ -292,22 +290,17 @@ void Paragraph::setChange(Change const & change)
 void Paragraph::setChange(pos_type pos, Change const & change)
 {
        BOOST_ASSERT(pos >= 0 && pos <= size());
-
        d->changes_.set(change, pos);
 
        // see comment in setChange(Change const &) above
-
-       if (change.type != Change::DELETED &&
-           pos < size() && isInset(pos)) {
+       if (change.type != Change::DELETED && pos < size() && isInset(pos))
                getInset(pos)->setChange(change);
-       }
 }
 
 
 Change const & Paragraph::lookupChange(pos_type pos) const
 {
        BOOST_ASSERT(pos >= 0 && pos <= size());
-
        return d->changes_.lookup(pos);
 }
 
index 12ed1b85d9ee12c8d6de915f50faaea6cb7af602..7b697e6fbc0bf866483236739e2dc4ed94404f81 100644 (file)
@@ -543,7 +543,7 @@ void Text::insertChar(Cursor & cur, char_type c)
        }
 
        par.insertChar(cur.pos(), c, cur.current_font, cur.buffer().params().trackChanges);
-       checkBufferStructure(cur.buffer(), cur);
+       cur.checkBufferStructure();
 
 //             cur.updateFlags(Update::Force);
        setCursor(cur.top(), cur.pit(), cur.pos() + 1);
@@ -795,7 +795,7 @@ void Text::deleteWordForward(Cursor & cur)
                cursorForwardOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
        }
 }
 
@@ -811,7 +811,7 @@ void Text::deleteWordBackward(Cursor & cur)
                cursorBackwardOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
        }
 }
 
@@ -855,7 +855,7 @@ void Text::changeCase(Cursor & cur, TextCase action)
        setCursor(cur, endPit, right);
        cur.setSelection();
 
-       checkBufferStructure(cur.buffer(), cur);
+       cur.checkBufferStructure();
 }
 
 
@@ -905,7 +905,7 @@ bool Text::erase(Cursor & cur)
                        // the character has been logically deleted only => skip it
                        cur.top().forwardPos();
                }
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
                needsUpdate = true;
        } else {
                if (cur.pit() == cur.lastpit())
@@ -927,7 +927,7 @@ bool Text::erase(Cursor & cur)
                // Make sure the cursor is correct. Is this really needed?
                // No, not really... at least not here!
                cur.text()->setCursor(cur.top(), cur.pit(), cur.pos());
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
        }
 
        return needsUpdate;
@@ -1015,7 +1015,7 @@ bool Text::backspace(Cursor & cur)
                setCursorIntern(cur, cur.pit(), cur.pos() - 1,
                                false, cur.boundary());
                cur.paragraph().eraseChar(cur.pos(), cur.buffer().params().trackChanges);
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
        }
 
        if (cur.pos() == cur.lastpos())
@@ -1384,7 +1384,7 @@ void Text::charsTranspose(Cursor & cur)
        par.insertChar(pos1, char2, font2, trackChanges);
        par.insertChar(pos2, char1, font1, trackChanges);
 
-       checkBufferStructure(cur.buffer(), cur);
+       cur.checkBufferStructure();
 
        // After the transposition, move cursor to after the transposition.
        setCursor(cur, cur.pit(), pos2);
index e1cf6591e4b856a9108ca8360653fdfb0324564b..360b3c772abf703f4075d20557e219641bd591fc 100644 (file)
@@ -1641,7 +1641,7 @@ void TextMetrics::deleteLineForward(Cursor & cur)
                        text_->deleteWordForward(cur);
                else
                        cap::cutSelection(cur, true, false);
-               checkBufferStructure(cur.buffer(), cur);
+               cur.checkBufferStructure();
        }
 }
 
index 54f5ece6d2d5172a3ef21f57c0a6f0eafeb564e6..1d90fa47775b1633c7202e567678afaa86abe9e5 100644 (file)
@@ -508,14 +508,4 @@ void updateLabels(Buffer const & buf, bool childonly)
 }
 
 
-void checkBufferStructure(Buffer & buffer, ParIterator const & par_it)
-{
-       if (par_it->layout()->toclevel != Layout::NOT_IN_TOC) {
-               Buffer const * master = buffer.masterBuffer();
-               master->tocBackend().updateItem(par_it);
-               master->structureChanged();
-       }
-}
-
-
 } // namespace lyx
index b5be3490d6d622e0c8d3350f4deaee8589686f0f..44ff0a37ed19f14658eebd719ea6d001f8302ab0 100644 (file)
@@ -53,9 +53,6 @@ void updateLabels(Buffer const &, bool childonly = false);
 ///
 void updateLabels(Buffer const &, ParIterator &);
 
-///
-void checkBufferStructure(Buffer &, ParIterator const &);
-
 } // namespace lyx
 
 #endif // BUFFER_FUNCS_H