]> git.lyx.org Git - features.git/commitdiff
~4% speedup by inlining a few one-line accessors
authorAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 11:00:15 +0000 (11:00 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 18 Jul 2005 11:00:15 +0000 (11:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10320 a592a061-630c-0410-9148-cb99ea01b6c8

src/cursor.C
src/cursor_slice.C
src/cursor_slice.h
src/insets/insettabular.C
src/lyxtext.h
src/mathed/math_hullinset.C
src/pariterator.C
src/rowpainter.C
src/text.C
src/text2.C
src/undo.C

index 0212621f350f0051545350774b4ec729da8b4b43..c15864e809e4ba1590913588594530374409de28 100644 (file)
@@ -1031,7 +1031,7 @@ string LCursor::selectionAsString(bool label) const
 
        if (inTexted()) {
                Buffer const & buffer = *bv().buffer();
-               ParagraphList & pars = text()->paragraphs();
+               ParagraphList const & pars = text()->paragraphs();
 
                // should be const ...
                pit_type startpit = selBegin().pit();
@@ -1048,7 +1048,7 @@ string LCursor::selectionAsString(bool label) const
 
                // The paragraphs in between (if any)
                for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
-                       Paragraph & par = pars[pit];
+                       Paragraph const & par = pars[pit];
                        result += par.asString(buffer, 0, par.size(), label) + "\n\n";
                }
 
index 086317800bf3364c3ab30ef3743c9c70c6ce328b..eda679a2e95750fa10c79da8517003c57dd63ba3 100644 (file)
@@ -38,24 +38,21 @@ CursorSlice::CursorSlice(InsetBase & p)
 }
 
 
-size_t CursorSlice::nargs() const
+MathArray & CursorSlice::cell() const
 {
-       BOOST_ASSERT(inset_);
-       return inset_->nargs();
+       return inset_->asMathInset()->cell(idx_);
 }
 
 
-size_t CursorSlice::nrows() const
+Paragraph & CursorSlice::paragraph()
 {
-       BOOST_ASSERT(inset_);
-       return inset_->nrows();
+       return text()->getPar(pit_);
 }
 
 
-size_t CursorSlice::ncols() const
+Paragraph const & CursorSlice::paragraph() const
 {
-       BOOST_ASSERT(inset_);
-       return inset_->ncols();
+       return text()->getPar(pit_);
 }
 
 
@@ -80,49 +77,6 @@ CursorSlice::col_type CursorSlice::col() const
 }
 
 
-MathInset * CursorSlice::asMathInset() const
-{
-       BOOST_ASSERT(inset_);
-       return inset_->asMathInset();
-}
-
-
-MathArray & CursorSlice::cell() const
-{
-       BOOST_ASSERT(asMathInset());
-       return asMathInset()->cell(idx_);
-}
-
-
-LyXText * CursorSlice::text()
-{
-       BOOST_ASSERT(inset_);
-       return inset_->getText(idx_);
-}
-
-LyXText const * CursorSlice::text() const
-{
-       BOOST_ASSERT(inset_);
-       return inset_->getText(idx_);
-}
-
-
-Paragraph & CursorSlice::paragraph()
-{
-       // access to the main lyx text must be handled in the cursor
-       BOOST_ASSERT(text());
-       return text()->getPar(pit_);
-}
-
-
-Paragraph const & CursorSlice::paragraph() const
-{
-       // access to the main lyx text must be handled in the cursor
-       BOOST_ASSERT(text());
-       return text()->getPar(pit_);
-}
-
-
 bool operator==(CursorSlice const & p, CursorSlice const & q)
 {
        return &p.inset() == &q.inset()
index 017def63a43b2e132208adcda3877122a3c80e92..3ba4dfb0587ba56d276f79488690535f2f864bc0 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef CURSORSLICE_H
 #define CURSORSLICE_H
 
+#include "insets/insetbase.h"
 #include "support/types.h"
 
 #include <cstddef>
@@ -29,7 +30,6 @@ class MathArray;
 class LyXText;
 class Paragraph;
 
-
 /// This encapsulates a single slice of a document iterator as used e.g.
 /// for cursors.
 
@@ -78,17 +78,11 @@ public:
        /// return the last position within the paragraph
        pos_type lastpos() const;
        /// return the number of embedded cells
-       size_t nargs() const;
-       /*!
-        * \return the number of columns.
-        * This does only make sense in grid like insets.
-        */
-       size_t ncols() const;
-       /*!
-        * \return the number of rows.
-        * This does only make sense in grid like insets.
-        */
-       size_t nrows() const;
+       size_t nargs() const { return inset_->nargs(); }
+       /// return the number of columns (1 in non-grid-like insets)
+       size_t ncols() const { return inset_->ncols(); }
+       /// return the number of rows (1 in non-grid-like insets)
+       size_t nrows() const { return inset_->nrows(); }
        /*!
         * \return the grid row of the current cell.
         * This does only make sense in grid like insets.
@@ -104,9 +98,9 @@ public:
        /// texted specific stuff
        ///
        /// returns text corresponding to this position
-       LyXText * text();
+       LyXText * text() { return inset_->getText(idx_); }
        /// returns text corresponding to this position
-       LyXText const * text() const;
+       LyXText const * text() const { return inset_->getText(idx_); }
        /// paragraph in this cell
        Paragraph & paragraph();
        /// paragraph in this cell
@@ -115,10 +109,10 @@ public:
        ///
        /// mathed specific stuff
        ///
+       /// returns the owning inset if it is a MathInset, else 0
+       MathInset * asMathInset() const { return inset_->asMathInset(); }
        /// returns cell corresponding to this position
        MathArray & cell() const;
-       /// returns the owning inset if it is a MathInset, else 0
-       MathInset * asMathInset() const;
 
        /// write some debug information to \p os
        friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
@@ -130,10 +124,8 @@ private:
         * Cell index of a position in this inset.
         * This is the primary cell information also for grid like insets,
         * although we have the convenience functions row() and col() for
-        * those.
-        * This means that the corresponding idx_ of a cell in a given row
-        * and column changes every time the number of columns or number of
-        * rows changes. Normally the cursor should stay in the same cell,
+        * those * and column changes every time the number of columns ornumber
+        * of rows changes. Normally the cursor should stay in the same cell,
         * so these changes should typically be performed like the following:
         * \code
         * row_type const r = cur.row();
index 0c9a755c5016aade5c10723265edc6256a153eac..7e3cd21e284d302ca933c6b10852e17071913c37 100644 (file)
@@ -980,7 +980,7 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_CELL_BACKWARD:
        case LFUN_CELL_FORWARD:
                status.enabled(true);
-                       return true;
+               return true;
 
        // disable these with multiple cells selected
        case LFUN_INSET_INSERT:
index 504366885db4df7b156e6f3dc7fde2815052aa9f..67825e9d0853ab0b9c32abbd38cd1504cfc073a5 100644 (file)
@@ -126,12 +126,12 @@ public:
                FuncStatus & status) const;
 
        /// access to out BufferView. This should go...
-//     BufferView * bv();
-       /// access to out BufferView. This should go...
        BufferView * bv() const;
 
-       /// access to individual paragraphs
-       Paragraph & getPar(pit_type par) const;
+       /// read-only access to individual paragraph
+       Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
+       /// read-write access to individual paragraph
+       Paragraph & getPar(pit_type pit) { return pars_[pit]; }
        // Returns the current font and depth as a message.
        std::string LyXText::currentState(LCursor & cur);
 
@@ -291,7 +291,8 @@ public:
        RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
 
        /// access to our paragraphs
-       ParagraphList & paragraphs() const;
+       ParagraphList const & paragraphs() const { return pars_; }
+       ParagraphList & paragraphs() { return pars_; }
        /// return true if this is the main text
        bool isMainText() const;
 
index 5539190a96d590fbced946fd1db3694fab4197ad..ba3204c7a4df4842dafcd3c267be8e0bfac15f61 100644 (file)
@@ -1433,9 +1433,9 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
        ms <<  "<graphic fileref=\"eqn/";
        if ( !label(0).empty())
                ms << sgml::cleanID(buf, runparams, label(0));
-       else {
+       else
                ms << sgml::uniqueID("anon");
-       }
+
        if (runparams.flavor == OutputParams::XML)
                ms << "\"/>";
        else
index e8eb521638a88905dc3bf95df49fc2d94b5e989b..c3c86765ed3e3d3fe51293c3c5e9fbf85470671f 100644 (file)
@@ -78,7 +78,7 @@ ParIterator & ParIterator::operator--()
 
 Paragraph & ParIterator::operator*() const
 {
-       return text()->getPar(pit());
+       return const_cast<Paragraph&>(text()->getPar(pit()));
 }
 
 
@@ -90,7 +90,7 @@ pit_type ParIterator::pit() const
 
 Paragraph * ParIterator::operator->() const
 {
-       return &text()->getPar(pit());
+       return const_cast<Paragraph*>(&text()->getPar(pit()));
 }
 
 
@@ -102,7 +102,7 @@ pit_type ParIterator::outerPar() const
 
 ParagraphList & ParIterator::plist() const
 {
-       return text()->paragraphs();
+       return const_cast<ParagraphList&>(text()->paragraphs());
 }
 
 
index d3c4a718f4b197ebc84c3ff009f718614ebf2d14..1c0e9dbf59ab5594775f54ec84d61b8d5c86aa4e 100644 (file)
@@ -99,7 +99,7 @@ private:
 
        /// LyXText for the row
        LyXText const & text_;
-       ParagraphList & pars_;
+       ParagraphList const & pars_;
 
        /// The row to paint
        Row const & row_;
@@ -732,7 +732,7 @@ void paintPar
        static PainterInfo nullpi(pi.base.bv, nop);
        int const ww = pi.base.bv->workHeight();
 
-       Paragraph & par = text.paragraphs()[pit];
+       Paragraph const & par = text.paragraphs()[pit];
 
        RowList::const_iterator const rb = par.rows().begin();
        RowList::const_iterator const re = par.rows().end();
index abeebe3a511e7309b75beb23bc4fefd7a76b4dc4..8824bd3b6c3deffb408d998ac381e9a2179dff68 100644 (file)
@@ -1665,15 +1665,6 @@ void LyXText::backspace(LCursor & cur)
 }
 
 
-Paragraph & LyXText::getPar(pit_type par) const
-{
-       //lyxerr << "getPar: " << par << " from " << paragraphs().size() << endl;
-       BOOST_ASSERT(par >= 0);
-       BOOST_ASSERT(par < int(paragraphs().size()));
-       return paragraphs()[par];
-}
-
-
 Row const & LyXText::firstRow() const
 {
        return *paragraphs().front().rows().begin();
index 9fcc8b3413459e5500efbd2a1daa3429e867cd92..4d88d64e22d81a0c96099b0caf61a76d1aba5cfa 100644 (file)
@@ -1082,7 +1082,8 @@ bool LyXText::cursorUp(LCursor & cur)
        } else if (cur.pit() > 0) {
                --cur.pit();
                //cannot use 'par' now
-               updateNeeded |= setCursor(cur, cur.pit(), x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
+               updateNeeded |= setCursor(cur, cur.pit(),
+      x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
        }
 
        cur.x_target() = x;
@@ -1308,12 +1309,6 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old)
 }
 
 
-ParagraphList & LyXText::paragraphs() const
-{
-       return const_cast<ParagraphList &>(pars_);
-}
-
-
 void LyXText::recUndo(pit_type first, pit_type last) const
 {
        recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
index 1a854a192c23af5f132b204203b62139aeebb4b6..075697facf327a269aa10b19d4b71dc12c50558e 100644 (file)
@@ -93,10 +93,10 @@ void doRecordUndo(Undo::undo_kind kind,
                // record the relevant paragraphs
                LyXText const * text = cell.text();
                BOOST_ASSERT(text);
-               ParagraphList & plist = text->paragraphs();
-               ParagraphList::iterator first = plist.begin();
+               ParagraphList const & plist = text->paragraphs();
+               ParagraphList::const_iterator first = plist.begin();
                advance(first, first_pit);
-               ParagraphList::iterator last = plist.begin();
+               ParagraphList::const_iterator last = plist.begin();
                advance(last, last_pit + 1);
                undo.pars = ParagraphList(first, last);
        }