mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
~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:
parent
18ed7fe334
commit
af5acb6dc7
@ -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";
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user