On Mon, Dec 12, 2005 at 02:57:50PM +0100, Jean-Marc Lasgouttes wrote: > Andre> While I cannot see anything getting worse, the par id still go > Andre> up quickly. More precisely, the id of the first par of the > Andre> UserGuide is 6183. Hit enter on the first line, then go down to > Andre> the par now containing the "The LyX User Guide" heading. With > Andre> this patch it has id 10294, without 12300 + x. So while there > Andre> is some improvement this does not seem to be the only problem. > > What I do not understand is why we use std::swap. Is that some clever > C++ idiom?
std::swap is reasonably fast on std::vector (siz pointer assignments or such) > For example SwitchBetweenLayouts does > > InsetText in; > std::swap(in.paragraphs(), pars); > > // layouts > ParIterator end = par_iterator_end(in); > for (ParIterator it = par_iterator_begin(in); it != end; ++it) { > [... etc ...] > > std::swap(in.paragraphs(), pars); > > So why don't we just remove these swap calls and be done with it? The problem here is that we get a ParagraphList passed but use some functions operating on InsetTexts there. So we create a temporary empty InsetText, swap in the paragraph list (which is fast), operate on the Inset and swap bacck if done. Everything else would involve copying the whole paragraph data (recursively...) and would be much more expensive. Andre'