On 10/01/2010 11:31, Abdelrazak Younes wrote:
On 10/01/2010 11:10, Abdelrazak Younes wrote:
On 10/01/2010 01:09, v...@lyx.org wrote:
Author: vfr
Date: Sun Jan 10 01:09:48 2010
New Revision: 32930
URL: http://www.lyx.org/trac/changeset/32930
Log:
Compare feature part 3: Implement the find_middle_snake algorithm.
The feature should now be up and running, although it might have
some performance issues. Please test with small changes :S as it
scales quadratic with the size of a single change.
If I look at DocRange::length() there is certainly a lot of room for
improvement ;-)
Like this for example (untested)? Maybe there is a reason why you
didn't do it that way?
With this patch, the feature seems to work fine with some minimal
changes in the UserGuide and quite fast too (15s).
Congratulations Vincent!
Abdel.
Index: Compare.cpp
===================================================================
--- Compare.cpp (revision 32931)
+++ Compare.cpp (working copy)
@@ -82,29 +82,15 @@
size_t DocRange::length() const
{
- pit_type startpit = from.pit();
- pit_type endpit = to.pit();
- ParagraphList const & ps_ = from.text()->paragraphs();
+ 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();
-
- size_t length = 0;
- for (; pit != end_it; ++pit)
- length += pit->size() + 1;
-
+ size_t pit = from.pit();
+ size_t length = ps[pit].size() - from.pos();
+ size_t const endpit = to.pit();
+ for (; pit < endpit; ++pit)
+ length += ps[pit].size() + 1;
// The last paragraph has no paragraph-end
- --length;
+ length += to.pos();
return length;
}