outline(): avoid paragraph copying by using RandomAccessList::splice().

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30961 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-08-09 20:25:20 +00:00
parent 856e95cf44
commit 673ff83263

View File

@ -388,10 +388,6 @@ static void outline(OutlineOp mode, Cursor & cur)
break; break;
} }
// Do we need to set insets' buffer_ members, because we copied
// some stuff? We'll assume we do and reset it otherwise.
bool set_buffers = true;
switch (mode) { switch (mode) {
case OutlineUp: { case OutlineUp: {
if (start == pars.begin()) if (start == pars.begin())
@ -415,10 +411,8 @@ static void outline(OutlineOp mode, Cursor & cur)
pit_type const len = distance(start, finish); pit_type const len = distance(start, finish);
pit_type const deletepit = pit + len; pit_type const deletepit = pit + len;
buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1); buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
pars.insert(dest, start, finish); pars.splice(dest, start, finish);
start = boost::next(pars.begin(), deletepit); cur.pit() = newpit;
pit = newpit;
pars.erase(start, finish);
break; break;
} }
case OutlineDown: { case OutlineDown: {
@ -436,12 +430,10 @@ static void outline(OutlineOp mode, Cursor & cur)
} }
// One such was found: // One such was found:
pit_type newpit = distance(bgn, dest); pit_type newpit = distance(bgn, dest);
pit_type const len = distance(start, finish);
buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1); buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
pars.insert(dest, start, finish); pit_type const len = distance(start, finish);
start = boost::next(bgn, pit); pars.splice(dest, start, finish);
pit = newpit - len; cur.pit() = newpit - len;
pars.erase(start, finish);
break; break;
} }
case OutlineIn: { case OutlineIn: {
@ -461,7 +453,6 @@ static void outline(OutlineOp mode, Cursor & cur)
} }
} }
} }
set_buffers = false;
break; break;
} }
case OutlineOut: { case OutlineOut: {
@ -481,20 +472,9 @@ static void outline(OutlineOp mode, Cursor & cur)
} }
} }
} }
set_buffers = false;
break; break;
} }
} }
if (set_buffers)
// FIXME This only really needs doing for the newly introduced
// paragraphs. Something like:
// pit_type const numpars = distance(start, finish);
// start = boost::next(bgn, pit);
// finish = boost::next(start, numpars);
// for (; start != finish; ++start)
// start->setBuffer(buf);
// But while this seems to work, it is kind of fragile.
buf.inset().setBuffer(buf);
} }