Martin Vermeer a écrit :
On Tue, Mar 28, 2006 at 08:30:29PM +0200, Abdelrazak Younes wrote:
Martin Vermeer a écrit :
Attached a slightly improved patch that will go into trunk unless
objections come up.
I have a comment with regard to your use of ParagraphList. Sorry I just noticed that now...
In your new function.

+void Outline(OutlineOp mode, Buffer * buf, pit_type & pit)

you use ParagraphList::iterator and at the end you compute the needed pit type with std::distance. AFAIS from your code, you could as well use operator[] directly. You will have greater speed as a result.

How? I don't quite see it.
Here is a modified version of your code (not tested and won't work because of missing method in RandomAccessList). It could be simplified even more thanks to direct access.

void Outline(OutlineOp mode, Buffer * buf, pit_type & pit)
{
   ParagraphList & pars = buf->text().paragraphs();
   pit_type bgn = 0;
   pit_type s = pit;
   pit_type p = pit;
   pit_type end = pars.size();

   LyXTextClass::const_iterator lit =
       buf->params().getLyXTextClass().begin();
   LyXTextClass::const_iterator const lend =
       buf->params().getLyXTextClass().end();

   int const thistoclevel = s->layout()->toclevel;
   int toclevel;
   switch (mode) {
       case UP: {
           if (p != end)
               ++p;
           for (; p != end; ++p) {
               toclevel = pars[p].layout()->toclevel;
               if (toclevel != LyXLayout::NOT_IN_TOC
                   && toclevel <= thistoclevel) {
break; }
           }
           size_t q = s;
           if (q != bgn)
               --q;
           else
               break;
           for (; q != bgn; --q) {
               toclevel = pars[q].layout()->toclevel;
               if (toclevel != LyXLayout::NOT_IN_TOC
                   && toclevel <= thistoclevel) {
break; }
           }
           pit_type const newpit = q; //std::distance(pars.begin(), q);
           pit_type const len = p - s; //std::distance(s, p);
           pit += len;
// Lars has deleted all my convenience methods in RandomAccessList
           // especially one that offered this one:
           pars.insert(q, s, p);
           s = pit;
           pit_type t = s + len;
           // and also this one:
           pars.erase(s, t);
           pit = newpit;
       break;
       }

Abdel.

Reply via email to