~4% speedup by inlining a few one-line accessors

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10320 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2005-07-18 11:00:15 +00:00
parent 18ed7fe334
commit af5acb6dc7
11 changed files with 39 additions and 106 deletions

View File

@ -1031,7 +1031,7 @@ string LCursor::selectionAsString(bool label) const
if (inTexted()) { if (inTexted()) {
Buffer const & buffer = *bv().buffer(); Buffer const & buffer = *bv().buffer();
ParagraphList & pars = text()->paragraphs(); ParagraphList const & pars = text()->paragraphs();
// should be const ... // should be const ...
pit_type startpit = selBegin().pit(); pit_type startpit = selBegin().pit();
@ -1048,7 +1048,7 @@ string LCursor::selectionAsString(bool label) const
// The paragraphs in between (if any) // The paragraphs in between (if any)
for (pit_type pit = startpit + 1; pit != endpit; ++pit) { 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"; result += par.asString(buffer, 0, par.size(), label) + "\n\n";
} }

View File

@ -38,24 +38,21 @@ CursorSlice::CursorSlice(InsetBase & p)
} }
size_t CursorSlice::nargs() const MathArray & CursorSlice::cell() const
{ {
BOOST_ASSERT(inset_); return inset_->asMathInset()->cell(idx_);
return inset_->nargs();
} }
size_t CursorSlice::nrows() const Paragraph & CursorSlice::paragraph()
{ {
BOOST_ASSERT(inset_); return text()->getPar(pit_);
return inset_->nrows();
} }
size_t CursorSlice::ncols() const Paragraph const & CursorSlice::paragraph() const
{ {
BOOST_ASSERT(inset_); return text()->getPar(pit_);
return inset_->ncols();
} }
@ -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) bool operator==(CursorSlice const & p, CursorSlice const & q)
{ {
return &p.inset() == &q.inset() return &p.inset() == &q.inset()

View File

@ -17,6 +17,7 @@
#ifndef CURSORSLICE_H #ifndef CURSORSLICE_H
#define CURSORSLICE_H #define CURSORSLICE_H
#include "insets/insetbase.h"
#include "support/types.h" #include "support/types.h"
#include <cstddef> #include <cstddef>
@ -29,7 +30,6 @@ class MathArray;
class LyXText; class LyXText;
class Paragraph; class Paragraph;
/// This encapsulates a single slice of a document iterator as used e.g. /// This encapsulates a single slice of a document iterator as used e.g.
/// for cursors. /// for cursors.
@ -78,17 +78,11 @@ public:
/// return the last position within the paragraph /// return the last position within the paragraph
pos_type lastpos() const; pos_type lastpos() const;
/// return the number of embedded cells /// return the number of embedded cells
size_t nargs() const; size_t nargs() const { return inset_->nargs(); }
/*! /// return the number of columns (1 in non-grid-like insets)
* \return the number of columns. size_t ncols() const { return inset_->ncols(); }
* This does only make sense in grid like insets. /// return the number of rows (1 in non-grid-like insets)
*/ size_t nrows() const { return inset_->nrows(); }
size_t ncols() const;
/*!
* \return the number of rows.
* This does only make sense in grid like insets.
*/
size_t nrows() const;
/*! /*!
* \return the grid row of the current cell. * \return the grid row of the current cell.
* This does only make sense in grid like insets. * This does only make sense in grid like insets.
@ -104,9 +98,9 @@ public:
/// texted specific stuff /// texted specific stuff
/// ///
/// returns text corresponding to this position /// returns text corresponding to this position
LyXText * text(); LyXText * text() { return inset_->getText(idx_); }
/// returns text corresponding to this position /// returns text corresponding to this position
LyXText const * text() const; LyXText const * text() const { return inset_->getText(idx_); }
/// paragraph in this cell /// paragraph in this cell
Paragraph & paragraph(); Paragraph & paragraph();
/// paragraph in this cell /// paragraph in this cell
@ -115,10 +109,10 @@ public:
/// ///
/// mathed specific stuff /// 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 /// returns cell corresponding to this position
MathArray & cell() const; MathArray & cell() const;
/// returns the owning inset if it is a MathInset, else 0
MathInset * asMathInset() const;
/// write some debug information to \p os /// write some debug information to \p os
friend std::ostream & operator<<(std::ostream &, CursorSlice const &); friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
@ -130,10 +124,8 @@ private:
* Cell index of a position in this inset. * Cell index of a position in this inset.
* This is the primary cell information also for grid like insets, * This is the primary cell information also for grid like insets,
* although we have the convenience functions row() and col() for * although we have the convenience functions row() and col() for
* those. * those * and column changes every time the number of columns ornumber
* This means that the corresponding idx_ of a cell in a given row * of rows changes. Normally the cursor should stay in the same cell,
* and column changes every time the number of columns or number of
* rows changes. Normally the cursor should stay in the same cell,
* so these changes should typically be performed like the following: * so these changes should typically be performed like the following:
* \code * \code
* row_type const r = cur.row(); * row_type const r = cur.row();

View File

@ -126,12 +126,12 @@ public:
FuncStatus & status) const; FuncStatus & status) const;
/// access to out BufferView. This should go... /// access to out BufferView. This should go...
// BufferView * bv();
/// access to out BufferView. This should go...
BufferView * bv() const; BufferView * bv() const;
/// access to individual paragraphs /// read-only access to individual paragraph
Paragraph & getPar(pit_type par) const; 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. // Returns the current font and depth as a message.
std::string LyXText::currentState(LCursor & cur); std::string LyXText::currentState(LCursor & cur);
@ -291,7 +291,8 @@ public:
RowMetrics computeRowMetrics(pit_type pit, Row const & row) const; RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
/// access to our paragraphs /// 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 /// return true if this is the main text
bool isMainText() const; bool isMainText() const;

View File

@ -1433,9 +1433,9 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
ms << "<graphic fileref=\"eqn/"; ms << "<graphic fileref=\"eqn/";
if ( !label(0).empty()) if ( !label(0).empty())
ms << sgml::cleanID(buf, runparams, label(0)); ms << sgml::cleanID(buf, runparams, label(0));
else { else
ms << sgml::uniqueID("anon"); ms << sgml::uniqueID("anon");
}
if (runparams.flavor == OutputParams::XML) if (runparams.flavor == OutputParams::XML)
ms << "\"/>"; ms << "\"/>";
else else

View File

@ -78,7 +78,7 @@ ParIterator & ParIterator::operator--()
Paragraph & ParIterator::operator*() const 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 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 ParagraphList & ParIterator::plist() const
{ {
return text()->paragraphs(); return const_cast<ParagraphList&>(text()->paragraphs());
} }

View File

@ -99,7 +99,7 @@ private:
/// LyXText for the row /// LyXText for the row
LyXText const & text_; LyXText const & text_;
ParagraphList & pars_; ParagraphList const & pars_;
/// The row to paint /// The row to paint
Row const & row_; Row const & row_;
@ -732,7 +732,7 @@ void paintPar
static PainterInfo nullpi(pi.base.bv, nop); static PainterInfo nullpi(pi.base.bv, nop);
int const ww = pi.base.bv->workHeight(); 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 rb = par.rows().begin();
RowList::const_iterator const re = par.rows().end(); RowList::const_iterator const re = par.rows().end();

View 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 Row const & LyXText::firstRow() const
{ {
return *paragraphs().front().rows().begin(); return *paragraphs().front().rows().begin();

View File

@ -1082,7 +1082,8 @@ bool LyXText::cursorUp(LCursor & cur)
} else if (cur.pit() > 0) { } else if (cur.pit() > 0) {
--cur.pit(); --cur.pit();
//cannot use 'par' now //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; 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 void LyXText::recUndo(pit_type first, pit_type last) const
{ {
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last); recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);

View File

@ -93,10 +93,10 @@ void doRecordUndo(Undo::undo_kind kind,
// record the relevant paragraphs // record the relevant paragraphs
LyXText const * text = cell.text(); LyXText const * text = cell.text();
BOOST_ASSERT(text); BOOST_ASSERT(text);
ParagraphList & plist = text->paragraphs(); ParagraphList const & plist = text->paragraphs();
ParagraphList::iterator first = plist.begin(); ParagraphList::const_iterator first = plist.begin();
advance(first, first_pit); advance(first, first_pit);
ParagraphList::iterator last = plist.begin(); ParagraphList::const_iterator last = plist.begin();
advance(last, last_pit + 1); advance(last, last_pit + 1);
undo.pars = ParagraphList(first, last); undo.pars = ParagraphList(first, last);
} }