Attached the summary of the speedup work over last week. It is a somewhat
intrusive patch, but it got some good testing and I believe we caught all
the side effects ;-)

Lars, can this go in?

- Martin


Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.595
diff -u -p -r1.595 BufferView_pimpl.C
--- BufferView_pimpl.C  15 Sep 2005 13:55:45 -0000      1.595
+++ BufferView_pimpl.C  25 Sep 2005 17:00:22 -0000
@@ -666,12 +666,12 @@ void BufferView::Pimpl::update(Update::f
                theCoords.startUpdating();
 
                // First drawing step
-               ViewMetricsInfo vi = metrics();
+               ViewMetricsInfo vi = metrics(flags & Update::SinglePar);
                bool forceupdate(flags & Update::Force);
 
                if ((flags & Update::FitCursor) && fitCursor()) {
                        forceupdate = true;
-                       vi = metrics(flags & Update::SinglePar);
+                       vi = metrics();
                }
                if (forceupdate) {
                        // Second drawing step
@@ -1327,23 +1327,22 @@ ViewMetricsInfo BufferView::Pimpl::metri
        int pit2 = pit;
        size_t const npit = text->paragraphs().size();
 
-       lyxerr[Debug::DEBUG]
-                << BOOST_CURRENT_FUNCTION
-                << " npit: " << npit
-                << " pit1: " << pit1
-                << " pit2: " << pit2
-                << endl;
-
-       // Rebreak anchor par
-       text->redoParagraph(pit);
-       int y0 = text->getPar(pit1).ascent() - offset_ref_;
+       // Rebreak anchor paragraph. In Single Paragraph mode, rebreak only
+       // the (main text, not inset!) paragraph containing the cursor.
+       // (if this paragraph contains insets etc., rebreaking will 
+       // recursively descend)
+       if (!singlepar || pit == cursor_.bottom().pit())
+               text->redoParagraph(pit);
+       int y0 = text->getPar(pit).ascent() - offset_ref_;
 
-       // Redo paragraphs above cursor if necessary
+       // Redo paragraphs above anchor if necessary; again, in Single Par
+       // mode, only if we encounter the (main text) one having the cursor.
        int y1 = y0;
-       while (!singlepar && y1 > 0 && pit1 > 0) {
+       while (y1 > 0 && pit1 > 0) {
                y1 -= text->getPar(pit1).ascent();
                --pit1;
-               text->redoParagraph(pit1);
+               if (!singlepar || pit1 == cursor_[0].pit())
+                       text->redoParagraph(pit1);
                y1 -= text->getPar(pit1).descent();
        }
 
@@ -1362,12 +1361,14 @@ ViewMetricsInfo BufferView::Pimpl::metri
                anchor_ref_ = 0;
        }
 
-       // Redo paragraphs below cursor if necessary
+       // Redo paragraphs below the anchor if necessary. Single par mode:
+       // only the one containing the cursor if encountered.
        int y2 = y0;
-       while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+       while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
                y2 += text->getPar(pit2).descent();
                ++pit2;
-               text->redoParagraph(pit2);
+               if (!singlepar || pit2 == cursor_.bottom().pit())
+                       text->redoParagraph(pit2);
                y2 += text->getPar(pit2).ascent();
        }
 
@@ -1379,13 +1380,28 @@ ViewMetricsInfo BufferView::Pimpl::metri
        for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
                y += text->getPar(pit).ascent();
                theCoords.parPos()[text][pit] = Point(0, y);
+               if (singlepar && pit == cursor_.bottom().pit()) {
+                       // In Single Paragraph mode, collect here the 
+                       // y1 and y2 of the (one) paragraph the cursor is in
+                       y1 = y - text->getPar(pit).ascent();
+                       y2 = y + text->getPar(pit).descent();
+               }
                y += text->getPar(pit).descent();
        }
 
+       if (singlepar) { // collect cursor paragraph iter bounds
+               pit1 = cursor_[0].pit();
+               pit2 = cursor_[0].pit();
+       }
+       }
        lyxerr[Debug::DEBUG]
                 << BOOST_CURRENT_FUNCTION
                 << " y1: " << y1
                 << " y2: " << y2
+                << " pit1: " << pit1
+                << " pit2: " << pit2
+                << " npit: " << npit
+                << " singlepar: " << singlepar
                 << endl;
 
        return ViewMetricsInfo(pit1, pit2, y1, y2, singlepar);
Index: lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.668
diff -u -p -r1.668 lyxfunc.C
--- lyxfunc.C   19 Sep 2005 09:55:49 -0000      1.668
+++ lyxfunc.C   25 Sep 2005 17:00:23 -0000
@@ -1556,8 +1556,6 @@ void LyXFunc::dispatch(FuncRequest const
                        // in (at least partially) visible top-level paragraphs.
                        if (update)
                                view()->update(Update::FitCursor | 
Update::Force);
-                       else
-                               view()->update(Update::FitCursor);
 
                        // if we executed a mutating lfun, mark the buffer as 
dirty
                        // FIXME: Why not use flag.enabled() but call getStatus 
again?
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.307
diff -u -p -r1.307 text3.C
--- text3.C     16 Sep 2005 10:06:09 -0000      1.307
+++ text3.C     25 Sep 2005 17:00:24 -0000
@@ -348,6 +348,7 @@ void LyXText::dispatch(LCursor & cur, Fu
                        needsUpdate = cursorLeftOneWord(cur);
                else
                        needsUpdate = cursorRightOneWord(cur);
+               cur.bv().update(Update::Force | Update::FitCursor);
                finishChange(cur, false);
                break;
 
@@ -358,6 +359,7 @@ void LyXText::dispatch(LCursor & cur, Fu
                        needsUpdate = cursorRightOneWord(cur);
                else
                        needsUpdate = cursorLeftOneWord(cur);
+               cur.bv().update(Update::Force | Update::FitCursor);
                finishChange(cur, false);
                break;
 
@@ -419,7 +421,8 @@ void LyXText::dispatch(LCursor & cur, Fu
                                && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_RIGHT);
-               }
+               } else
+                       cur.bv().update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_LEFT:
@@ -435,7 +438,8 @@ void LyXText::dispatch(LCursor & cur, Fu
                        && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
-               }
+               } else
+                       cur.bv().update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_UP:
@@ -449,7 +453,8 @@ void LyXText::dispatch(LCursor & cur, Fu
                          && cur.boundary() == oldBoundary) {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_UP);
-               }
+               } else
+                       cur.bv().update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_DOWN:
@@ -463,13 +468,15 @@ void LyXText::dispatch(LCursor & cur, Fu
                {
                        cur.undispatched();
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
-               }
+               } else
+                       cur.bv().update(Update::Force | Update::FitCursor);
                break;
 
        case LFUN_UP_PARAGRAPH:
                if (!cur.mark())
                        cur.clearSelection();
                needsUpdate = cursorUpParagraph(cur);
+               cur.bv().update(Update::Force | Update::FitCursor);
                finishChange(cur, false);
                break;
 
@@ -484,6 +491,7 @@ void LyXText::dispatch(LCursor & cur, Fu
                if (!cur.mark())
                        cur.clearSelection();
                needsUpdate = cursorDownParagraph(cur);
+               cur.bv().update(Update::Force | Update::FitCursor);
                finishChange(cur, false);
                break;
 
@@ -562,6 +570,7 @@ void LyXText::dispatch(LCursor & cur, Fu
                        cmd = FuncRequest(LFUN_FINISHED_UP);
                } else {
                        needsUpdate = cursorPrevious(cur);
+                       cur.bv().update(Update::Force | Update::FitCursor);
                }
                break;
 
@@ -576,6 +585,7 @@ void LyXText::dispatch(LCursor & cur, Fu
                        cmd = FuncRequest(LFUN_FINISHED_DOWN);
                } else {
                        needsUpdate = cursorNext(cur);
+                       cur.bv().update(Update::Force | Update::FitCursor);
                }
                break;
 
@@ -1117,6 +1127,9 @@ void LyXText::dispatch(LCursor & cur, Fu
                current_font.setLanguage(lang);
                real_current_font.setLanguage(lang);
 
+               // Remember the old paragraph metric
+               Dimension olddim = cur.paragraph().dim();
+
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
                for (; cit != end; ++cit)
@@ -1125,11 +1138,13 @@ void LyXText::dispatch(LCursor & cur, Fu
 
                cur.resetAnchor();
                moveCursor(cur, false);
-
-               needsUpdate = redoParagraph(cur.pit());
+               needsUpdate = cur.paragraph().dim().asc != olddim.asc ||
+                             cur.paragraph().dim().des != olddim.des;
                if (!needsUpdate) {
                        // update only this paragraph
                        cur.bv().update(Update::SinglePar | Update::Force);
+               } else {
+                       cur.bv().update(Update::Force | Update::FitCursor);
                }
 
                bv->updateScrollbar();
Index: frontends/qt2/QContentPane.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QContentPane.C,v
retrieving revision 1.35
diff -u -p -r1.35 QContentPane.C
--- frontends/qt2/QContentPane.C        6 Jun 2005 12:34:28 -0000       1.35
+++ frontends/qt2/QContentPane.C        25 Sep 2005 17:00:25 -0000
@@ -104,7 +104,7 @@ QContentPane::QContentPane(QWorkArea * p
                this, SLOT(scrollBarChanged(int)));
 
        // Start the timer, one-shot.
-       step_timer_.start(25, true);
+       step_timer_.start(50, true);
 }
 
 

Reply via email to