mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 03:36:39 +00:00
Optimize DocRange::length(). Thanks Abdel.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32938 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
fd0dfe1b79
commit
715b1303da
@ -84,29 +84,13 @@ public:
|
||||
|
||||
size_t DocRange::length() const
|
||||
{
|
||||
pit_type startpit = from.pit();
|
||||
pit_type endpit = to.pit();
|
||||
ParagraphList const & ps_ = from.text()->paragraphs();
|
||||
|
||||
ParagraphList pars(boost::next(ps_.begin(), startpit),
|
||||
boost::next(ps_.begin(), endpit + 1));
|
||||
|
||||
// Remove the end of the last paragraph; afterwards, remove the
|
||||
// beginning of the first paragraph.
|
||||
Paragraph & back = pars.back();
|
||||
back.eraseChars(to.pos(), back.size(), false);
|
||||
Paragraph & front = pars.front();
|
||||
front.eraseChars(0, from.pos(), false);
|
||||
|
||||
ParagraphList::const_iterator pit = pars.begin();
|
||||
ParagraphList::const_iterator end_it = pars.end();
|
||||
|
||||
ParagraphList const & ps = from.text()->paragraphs();
|
||||
size_t length = 0;
|
||||
for (; pit != end_it; ++pit)
|
||||
length += pit->size() + 1;
|
||||
|
||||
// The last paragraph has no paragraph-end
|
||||
--length;
|
||||
pit_type pit = from.pit();
|
||||
pit_type const endpit = to.pit();
|
||||
for (; pit < endpit; ++pit)
|
||||
length += ps[pit].size() + 1;
|
||||
length += to.pos() - from.pos();
|
||||
return length;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user