]> git.lyx.org Git - features.git/commitdiff
* Paragraph: reserve memory by chunks of 100 chars. This improve the loading of big...
authorAbdelrazak Younes <younes@lyx.org>
Mon, 22 Oct 2007 20:05:41 +0000 (20:05 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Mon, 22 Oct 2007 20:05:41 +0000 (20:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21127 a592a061-630c-0410-9148-cb99ea01b6c8

src/Paragraph.cpp

index f123c80764278eab14f00ee54c1f666193dcfa4f..2bd9f45f2488064b5d453c2bd74dd787fbfda86f 100644 (file)
@@ -988,6 +988,7 @@ Paragraph::Paragraph()
 {
        itemdepth = 0;
        d->params_.clear();
+       text_.reserve(100);
 }
 
 
@@ -1153,16 +1154,20 @@ void Paragraph::appendString(docstring const & s, Font const & font,
                Change const & change)
 {
        size_t end = s.size();
-       pos_type startpos = text_.size();
+       size_t oldsize = text_.size();
+       size_t newsize = oldsize + end;
+       size_t capacity = text_.capacity();
+       if (newsize >= capacity)
+               text_.reserve(std::max(capacity + 100, newsize));
+
        // FIXME: Optimize this!
-       text_.reserve(startpos + end);
        for (pos_type i = 0; i != end; ++i) {
                // track change
                d->changes_.insert(change, i);
                // when appending characters, no need to update tables
                text_.push_back(s[i]);
        }
-       d->fontlist_.setRange(startpos, text_.size(), font);
+       d->fontlist_.setRange(oldsize, newsize, font);
 }