From 3911d72568b8729061fd4e59a6dec5b0d8996762 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Mon, 22 Oct 2007 20:05:41 +0000 Subject: [PATCH] * Paragraph: reserve memory by chunks of 100 chars. This improve the loading of big document of about 15% (12s instead of 14s for the UserGuide copied and pasted 10 times). There is zero penalty memory wise; quite weirdly, there is a benefit actually: 58 Megs instead 60 Megs, I don't understand why. For comparison, 1.5 needs 78 Megs for the same document. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21127 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Paragraph.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index f123c80764..2bd9f45f24 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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); } -- 2.39.5