]> git.lyx.org Git - features.git/commitdiff
speed up workWidth code
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 19 Oct 2001 12:34:31 +0000 (12:34 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 19 Oct 2001 12:34:31 +0000 (12:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2900 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/text.C

index e0e5449d892d86d9c84f20a7f12bb299d689c589..d6a6ecf05dc3777bfc1396a4cf38befa1790bc45 100644 (file)
@@ -1,3 +1,9 @@
+2001-10-19  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
+
+       * text.C (workWidth): do not search for the exact row when
+       margintype is not MARGIN_RIGHT_ADDRESS_BOX. This is an
+       optimization for big documents.
+
 2001-10-18  Juergen Vigna  <jug@sad.it>
 
        * text.C (workWidth): new function with added Inset * parameter.
index 731ae3282cb29e67733cf90590f69db18336ba95..02afce8f7d1b087ec3ca4659d84044e895a11ea8 100644 (file)
@@ -68,7 +68,7 @@ int LyXText::workWidth(BufferView * bview, Inset * inset) const
 {
        Buffer::inset_iterator it;
        Paragraph * par = 0;
-       Paragraph::size_type pos;
+       Paragraph::size_type pos = 0;
 
        for(it=bview->buffer()->inset_iterator_begin();
            it != bview->buffer()->inset_iterator_end();
@@ -80,20 +80,38 @@ int LyXText::workWidth(BufferView * bview, Inset * inset) const
                        break;
                }
        }
-       if (par) {
+       
+       if (!par) {
+               lyxerr << "LyXText::workWidth: cannot find inset!" <<endl;
+               return workWidth(bview);
+       }
+       
+       LyXLayout const & layout =
+               textclasslist.Style(bview->buffer()->params.textclass,
+                                   par->getLayout());
+
+       if (layout.margintype != MARGIN_RIGHT_ADDRESS_BOX) {
+               // Optimization here: in most cases, the real row is
+               // not needed, but only the par/pos values. So we just
+               // construct a dummy row for leftMargin. (JMarc)
+               Row dummyrow;
+               dummyrow.par(par);
+               dummyrow.pos(pos);
+               return workWidth(bview) - leftMargin(bview, &dummyrow);
+       } else {
                Row * row = firstrow;
                for(; row; row = row->next()) {
                        if ((row->par() == par && row->pos() >= pos)) {
                                if (!row->next())
                                        break;
                                else if ((row->next()->par() == par) &&
-                                                (row->next()->pos() >= pos))
+                                        (row->next()->pos() >= pos))
                                        continue;
                        }
                }
                if (row) {
                        return workWidth(bview) - leftMargin(bview, row);
-               }
+               } 
        }
        return workWidth(bview);
 }