mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
Paragraph::write: buffer normal characters into a docstring, in order to reduce the number of calls to to_qstr().
THis leads to a big speedup of the buffer-write function (>60%). The goal is to make autosave less noticeable. This patch should be safe as long as transforming a docstring to utf8 is equivalent to transforming the characters one by one. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31695 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1535e4b825
commit
b265203a84
@ -1168,6 +1168,18 @@ Paragraph::~Paragraph()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// this shall be called just before every "os << ..." action.
|
||||||
|
void flushString(ostream & os, docstring & s)
|
||||||
|
{
|
||||||
|
os << to_utf8(s);
|
||||||
|
s.erase();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Paragraph::write(ostream & os, BufferParams const & bparams,
|
void Paragraph::write(ostream & os, BufferParams const & bparams,
|
||||||
depth_type & dth) const
|
depth_type & dth) const
|
||||||
{
|
{
|
||||||
@ -1195,10 +1207,16 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
|
|
||||||
Change running_change = Change(Change::UNCHANGED);
|
Change running_change = Change(Change::UNCHANGED);
|
||||||
|
|
||||||
|
// this string is used as a buffer to avoid repetitive calls
|
||||||
|
// to to_utf8(), which turn out to be expensive (JMarc)
|
||||||
|
docstring write_buffer;
|
||||||
|
|
||||||
int column = 0;
|
int column = 0;
|
||||||
for (pos_type i = 0; i <= size(); ++i) {
|
for (pos_type i = 0; i <= size(); ++i) {
|
||||||
|
|
||||||
Change const change = lookupChange(i);
|
Change const change = lookupChange(i);
|
||||||
|
if (change != running_change)
|
||||||
|
flushString(os, write_buffer);
|
||||||
Changes::lyxMarkChange(os, bparams, column, running_change, change);
|
Changes::lyxMarkChange(os, bparams, column, running_change, change);
|
||||||
running_change = change;
|
running_change = change;
|
||||||
|
|
||||||
@ -1209,6 +1227,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
Font font2 = getFontSettings(bparams, i);
|
Font font2 = getFontSettings(bparams, i);
|
||||||
font2.setMisspelled(false);
|
font2.setMisspelled(false);
|
||||||
if (font2 != font1) {
|
if (font2 != font1) {
|
||||||
|
flushString(os, write_buffer);
|
||||||
font2.lyxWriteChanges(font1, os);
|
font2.lyxWriteChanges(font1, os);
|
||||||
column = 0;
|
column = 0;
|
||||||
font1 = font2;
|
font1 = font2;
|
||||||
@ -1218,6 +1237,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
switch (c) {
|
switch (c) {
|
||||||
case META_INSET:
|
case META_INSET:
|
||||||
if (Inset const * inset = getInset(i)) {
|
if (Inset const * inset = getInset(i)) {
|
||||||
|
flushString(os, write_buffer);
|
||||||
if (inset->directWrite()) {
|
if (inset->directWrite()) {
|
||||||
// international char, let it write
|
// international char, let it write
|
||||||
// code directly so it's shorter in
|
// code directly so it's shorter in
|
||||||
@ -1234,10 +1254,12 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\\':
|
case '\\':
|
||||||
|
flushString(os, write_buffer);
|
||||||
os << "\n\\backslash\n";
|
os << "\n\\backslash\n";
|
||||||
column = 0;
|
column = 0;
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
|
flushString(os, write_buffer);
|
||||||
if (i + 1 < size() && d->text_[i + 1] == ' ') {
|
if (i + 1 < size() && d->text_[i + 1] == ' ') {
|
||||||
os << ".\n";
|
os << ".\n";
|
||||||
column = 0;
|
column = 0;
|
||||||
@ -1247,13 +1269,14 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
default:
|
default:
|
||||||
if ((column > 70 && c == ' ')
|
if ((column > 70 && c == ' ')
|
||||||
|| column > 79) {
|
|| column > 79) {
|
||||||
|
flushString(os, write_buffer);
|
||||||
os << '\n';
|
os << '\n';
|
||||||
column = 0;
|
column = 0;
|
||||||
}
|
}
|
||||||
// this check is to amend a bug. LyX sometimes
|
// this check is to amend a bug. LyX sometimes
|
||||||
// inserts '\0' this could cause problems.
|
// inserts '\0' this could cause problems.
|
||||||
if (c != '\0')
|
if (c != '\0')
|
||||||
os << to_utf8(docstring(1, c));
|
write_buffer.push_back(c);
|
||||||
else
|
else
|
||||||
LYXERR0("NUL char in structure.");
|
LYXERR0("NUL char in structure.");
|
||||||
++column;
|
++column;
|
||||||
@ -1261,6 +1284,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flushString(os, write_buffer);
|
||||||
os << "\n\\end_layout\n";
|
os << "\n\\end_layout\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user