]> git.lyx.org Git - lyx.git/blobdiff - src/Compare.cpp
Part of r32942. We want to avoid reload flickering when
[lyx.git] / src / Compare.cpp
index 37989a8986ca7760aafe2d053618bdeec247d2e3..95eaf5abaef0f9cc1bf3eacfc89297b7348d8062 100644 (file)
@@ -84,30 +84,14 @@ 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;
-       return 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;
 }
 
 
@@ -206,13 +190,14 @@ public:
                Vn_.clear();
        }
 
+       /// Gets the value at index. If it is not in the vector
+       /// the default value is inserted and returned.
        T & operator[](int index) {
                vector<T> & V = index >= 0 ? Vp_ : Vn_;
-               if (index < 0)
-                       index = -index-1;
-               while (index >= V.size())
+               unsigned int const ii = index >= 0 ? index : -index - 1;
+               while (ii >= V.size())
                        V.push_back(default_);
-               return V[index];
+               return V[ii];
        }
 
 private: