Hmm... would it make sense to copy or otherwise arrange to have a paragraph
subject to mangling in a larger buffer split into two pieces (before and after
the cursor)? This is very efficient for insertations and deletions
anywhere---all it takes is adjusting a pointer and nothing special applies to
either end of the paragraph. Memory overhead is a couple of pointers and the
extra space in the buffer.
InsertChar in in LyxParagraph looks like it is a lot less efficient,
expecially if I insert vast amounts of text close to the beginning of a long
paragraph. A split buffer is cheap in this instance (in my outline below
endtop just increases by a lot).
void LyXParagraph::InsertChar(int pos, char c)
{
<... stuff snipped ,..>
// Shift rest of character
for (i = last; i>pos; i--) {
text[i]=text[i-1];
}
<...rest of function snipped ...>
}
Using a memory layout of
Blah Blah<cursor> <free space>blah blah.
^ ^ ^ ^
text endtop beginbot text+size
inserting a character becomes
<... stuff snipped ...>
// Are we full?
if (begintop == endbot) {
int l;
l=text+size-endbot;
char *temp = new char[size+STEP_SIZE_PAR];
if (begintop>text)
memcpy(temp, text, begintop-text);
if (endbot<text+(size-STEP_SIZE_PAR))
memcpy(temp+(size+STEP_SIZE_PAR-l), text+size-l, l);
size += STEP_SIZE_PAR;
endbot=temp+(endbot-text));
begintop=temp+size-l;
delete[](text);
text=temp;
}
// Now insert the character
assert(endtop<beginbot); // Sanity test
*(endtop++)=c;
<...rest of function snipped...>
What impact would this change have on the rest of the code? I can see the need to
track cursor movement and paragraph painter as the obvious issues.
--
Duncan (-:
"software industry, the: unique industry where selling substandard goods is
legal and you can charge extra for fixing the problems."