mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
un-pimpl Paragraph::(Pimpl::)text for performance reasons
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7773 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
f5a0bad734
commit
034f172087
@ -1,3 +1,10 @@
|
||||
|
||||
2003-09-16 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* paragraph.[Ch]:
|
||||
* paragraph_pimpl.[Ch]: un-pimpl Paragraph::(Pimpl::)text for a >10%
|
||||
performance boost.
|
||||
|
||||
2003-09-16 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* lyxfont.h (LyXFont_size): a wrapper class for LyXFont::FONT_SIZE.
|
||||
|
@ -60,7 +60,7 @@ Paragraph::Paragraph()
|
||||
|
||||
|
||||
Paragraph::Paragraph(Paragraph const & lp)
|
||||
: y(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
|
||||
: y(0), text_(lp.text_), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this))
|
||||
{
|
||||
enumdepth = 0;
|
||||
itemdepth = 0;
|
||||
@ -87,6 +87,8 @@ void Paragraph::operator=(Paragraph const & lp)
|
||||
|
||||
lyxerr << "Paragraph::operator=()" << endl;
|
||||
|
||||
text_ = lp.text_;
|
||||
|
||||
delete pimpl_;
|
||||
pimpl_ = new Pimpl(*lp.pimpl_, this);
|
||||
|
||||
@ -1270,21 +1272,21 @@ void Paragraph::rejectChange(pos_type start, pos_type end)
|
||||
}
|
||||
|
||||
|
||||
lyx::pos_type Paragraph::size() const
|
||||
{
|
||||
return pimpl_->size();
|
||||
}
|
||||
|
||||
|
||||
bool Paragraph::empty() const
|
||||
{
|
||||
return pimpl_->empty();
|
||||
}
|
||||
|
||||
|
||||
Paragraph::value_type Paragraph::getChar(pos_type pos) const
|
||||
{
|
||||
return pimpl_->getChar(pos);
|
||||
// This is in the critical path!
|
||||
pos_type const siz = text_.size();
|
||||
|
||||
BOOST_ASSERT(pos <= siz);
|
||||
|
||||
if (pos == siz) {
|
||||
lyxerr << "getChar() on pos " << pos << " in par id "
|
||||
<< id() << " of size " << siz
|
||||
<< " is a bit silly !" << endl;
|
||||
return '\0';
|
||||
}
|
||||
|
||||
return text_[pos];
|
||||
}
|
||||
|
||||
|
||||
@ -1325,12 +1327,13 @@ UpdatableInset * Paragraph::inInset() const
|
||||
|
||||
void Paragraph::clearContents()
|
||||
{
|
||||
pimpl_->clear();
|
||||
text_.clear();
|
||||
}
|
||||
|
||||
|
||||
void Paragraph::setChar(pos_type pos, value_type c)
|
||||
{
|
||||
pimpl_->setChar(pos, c);
|
||||
text_[pos] = c;
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,6 +56,8 @@ public:
|
||||
typedef char value_type;
|
||||
///
|
||||
typedef lyx::depth_type depth_type;
|
||||
///
|
||||
typedef std::vector<value_type> TextContainer;
|
||||
|
||||
///
|
||||
Paragraph();
|
||||
@ -120,9 +122,9 @@ public:
|
||||
void deleteInsetsLyXText(BufferView *);
|
||||
|
||||
///
|
||||
lyx::pos_type size() const;
|
||||
lyx::pos_type size() const { return text_.size(); }
|
||||
///
|
||||
bool empty() const;
|
||||
bool empty() const { return text_.empty(); }
|
||||
///
|
||||
void setContentsFromPar(Paragraph const & par);
|
||||
///
|
||||
@ -307,6 +309,9 @@ public:
|
||||
private:
|
||||
///
|
||||
LyXLayout_ptr layout_;
|
||||
/// keeping this here instead of in the pimpl makes LyX >10% faster
|
||||
// for average tasks as buffer loading/switching etc.
|
||||
TextContainer text_;
|
||||
|
||||
struct Pimpl;
|
||||
///
|
||||
|
@ -72,7 +72,6 @@ Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
|
||||
: params(p.params), owner_(owner)
|
||||
{
|
||||
inset_owner = p.inset_owner;
|
||||
text = p.text;
|
||||
fontlist = p.fontlist;
|
||||
id_ = paragraph_id++;
|
||||
|
||||
@ -81,16 +80,9 @@ Paragraph::Pimpl::Pimpl(Pimpl const & p, Paragraph * owner)
|
||||
}
|
||||
|
||||
|
||||
void Paragraph::Pimpl::clear()
|
||||
{
|
||||
text.clear();
|
||||
#warning changes ?
|
||||
}
|
||||
|
||||
|
||||
void Paragraph::Pimpl::setContentsFromPar(Paragraph const & par)
|
||||
{
|
||||
text = par.pimpl_->text;
|
||||
owner_->text_ = par.text_;
|
||||
if (par.pimpl_->tracking()) {
|
||||
changes_.reset(new Changes(*(par.pimpl_->changes_.get())));
|
||||
}
|
||||
@ -256,31 +248,7 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
|
||||
|
||||
Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
|
||||
{
|
||||
#if 1
|
||||
// This is in the critical path for loading!
|
||||
pos_type const siz = size();
|
||||
|
||||
BOOST_ASSERT(pos <= siz);
|
||||
|
||||
if (pos == siz) {
|
||||
lyxerr << "getChar() on pos " << pos << " in par id "
|
||||
<< owner_->id() << " of size " << siz
|
||||
<< " is a bit silly !" << endl;
|
||||
return '\0';
|
||||
}
|
||||
|
||||
return text[pos];
|
||||
#else
|
||||
BOOST_ASSERT(pos < size());
|
||||
return text[pos];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Paragraph::Pimpl::setChar(pos_type pos, value_type c)
|
||||
{
|
||||
#warning changes
|
||||
text[pos] = c;
|
||||
return owner_->getChar(pos);
|
||||
}
|
||||
|
||||
|
||||
@ -297,12 +265,12 @@ void Paragraph::Pimpl::insertChar(pos_type pos, value_type c,
|
||||
// maybe inserting ascii text)
|
||||
if (pos == size()) {
|
||||
// when appending characters, no need to update tables
|
||||
text.push_back(c);
|
||||
owner_->text_.push_back(c);
|
||||
owner_->setFont(pos, font);
|
||||
return;
|
||||
}
|
||||
|
||||
text.insert(text.begin() + pos, c);
|
||||
owner_->text_.insert(owner_->text_.begin() + pos, c);
|
||||
|
||||
// Update the font table.
|
||||
FontTable search_font(pos, LyXFont());
|
||||
@ -328,7 +296,7 @@ void Paragraph::Pimpl::insertInset(pos_type pos,
|
||||
BOOST_ASSERT(pos <= size());
|
||||
|
||||
insertChar(pos, META_INSET, font, change);
|
||||
BOOST_ASSERT(text[pos] == META_INSET);
|
||||
BOOST_ASSERT(owner_->text_[pos] == META_INSET);
|
||||
|
||||
// Add a new entry in the insetlist.
|
||||
owner_->insetlist.insert(inset, pos);
|
||||
@ -341,11 +309,11 @@ void Paragraph::Pimpl::insertInset(pos_type pos,
|
||||
void Paragraph::Pimpl::eraseIntern(pos_type pos)
|
||||
{
|
||||
// if it is an inset, delete the inset entry
|
||||
if (text[pos] == Paragraph::META_INSET) {
|
||||
if (owner_->text_[pos] == Paragraph::META_INSET) {
|
||||
owner_->insetlist.erase(pos);
|
||||
}
|
||||
|
||||
text.erase(text.begin() + pos);
|
||||
owner_->text_.erase(owner_->text_.begin() + pos);
|
||||
|
||||
// Erase entries in the tables.
|
||||
FontTable search_font(pos, LyXFont());
|
||||
@ -392,7 +360,7 @@ bool Paragraph::Pimpl::erase(pos_type pos)
|
||||
|
||||
// only allow the actual removal if it was /new/ text
|
||||
if (changetype != Change::INSERTED) {
|
||||
if (text[pos] == Paragraph::META_INSET) {
|
||||
if (owner_->text_[pos] == Paragraph::META_INSET) {
|
||||
InsetOld * i(owner_->getInset(pos));
|
||||
i->markErased();
|
||||
}
|
||||
@ -463,7 +431,7 @@ bool Paragraph::Pimpl::isTextAt(string const & str, pos_type pos) const
|
||||
|
||||
// does the wanted text start at point?
|
||||
for (string::size_type i = 0; i < str.length(); ++i) {
|
||||
if (str[i] != text[pos + i])
|
||||
if (str[i] != owner_->text_[pos + i])
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,24 +25,11 @@
|
||||
class LyXLayout;
|
||||
|
||||
struct Paragraph::Pimpl {
|
||||
///
|
||||
typedef std::vector<value_type> TextContainer;
|
||||
|
||||
///
|
||||
Pimpl(Paragraph * owner);
|
||||
/// Copy constructor
|
||||
Pimpl(Pimpl const &, Paragraph * owner);
|
||||
///
|
||||
lyx::pos_type size() const {
|
||||
return text.size();
|
||||
}
|
||||
///
|
||||
bool empty() const {
|
||||
return text.empty();
|
||||
}
|
||||
///
|
||||
void clear();
|
||||
///
|
||||
void setContentsFromPar(Paragraph const & par);
|
||||
/// set tracking mode
|
||||
void trackChanges(Change::Type type = Change::UNCHANGED);
|
||||
@ -182,6 +169,8 @@ struct Paragraph::Pimpl {
|
||||
ParagraphParameters params;
|
||||
|
||||
private:
|
||||
///
|
||||
lyx::pos_type size() const { return owner_->size(); }
|
||||
/// match a string against a particular point in the paragraph
|
||||
bool isTextAt(string const & str, lyx::pos_type pos) const;
|
||||
|
||||
@ -190,8 +179,6 @@ private:
|
||||
|
||||
/// Who owns us?
|
||||
Paragraph * owner_;
|
||||
///
|
||||
TextContainer text;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user