From ebcb289b7ce736f63f743a5cd56e8d2e7cbd3254 Mon Sep 17 00:00:00 2001 From: Martin Vermeer Date: Fri, 7 Oct 2005 12:00:41 +0000 Subject: [PATCH] The speedup patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10528 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 52 +++++++++++++++++++++----------- src/ChangeLog | 13 ++++++++ src/LyXAction.C | 6 ++-- src/LyXAction.h | 3 +- src/frontends/qt2/ChangeLog | 5 +++ src/frontends/qt2/QContentPane.C | 2 +- src/rowpainter.C | 16 +++++----- src/text3.C | 25 ++++++++++----- 8 files changed, 83 insertions(+), 39 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 9618481778..7b1fa8db6f 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -666,12 +666,12 @@ void BufferView::Pimpl::update(Update::flags flags) 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::metrics(bool singlepar) 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 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_; - // Rebreak anchor par - text->redoParagraph(pit); - int y0 = text->getPar(pit1).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_.bottom().pit()) + text->redoParagraph(pit1); y1 -= text->getPar(pit1).descent(); } @@ -1362,12 +1361,14 @@ ViewMetricsInfo BufferView::Pimpl::metrics(bool singlepar) 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::metrics(bool singlepar) 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_.bottom().pit(); + pit2 = cursor_.bottom().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); diff --git a/src/ChangeLog b/src/ChangeLog index 2dd8e7b854..ff33553b42 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,16 @@ +2005-10-07 Martin Vermeer + + * BufferView_pimpl.C (update): choose arguments to update call so + that single-par update works most times + * text3.C (dispatch): carefully tune updating separately for + whole-screen and current-paragraph + * rowpainter.C (paintText): 1) replace painting by caching for + the two extra paragraphs, because we can; + 2) suppress greying out of areas below/above drawn area in case of + single-par refresh + * lyxfunc.C (dispatch): remove superfluous update + * LyXAction.[Ch]: introduce SingleParUpdate + 2005-10-05 Angus Leeming * BufferView_pimpl.C (loadLyXFile): ensure that a pointer is diff --git a/src/LyXAction.C b/src/LyXAction.C index 18d98f60c1..97cd7949c6 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -136,9 +136,9 @@ void LyXAction::init() { LFUN_COPY, "copy", ReadOnly }, { LFUN_CUT, "cut", Noop }, { LFUN_DATE_INSERT, "date-insert", Noop }, - { LFUN_BACKSPACE, "delete-backward", Noop }, + { LFUN_BACKSPACE, "delete-backward", SingleParUpdate }, { LFUN_BACKSPACE_SKIP, "delete-backward-skip", Noop }, - { LFUN_DELETE, "delete-forward", Noop }, + { LFUN_DELETE, "delete-forward", SingleParUpdate }, { LFUN_DELETE_SKIP, "delete-forward-skip", Noop }, { LFUN_DEPTH_MIN, "depth-decrement", Noop }, { LFUN_DEPTH_PLUS, "depth-increment", Noop }, @@ -257,7 +257,7 @@ void LyXAction::init() { LFUN_PRIOR, "screen-up", ReadOnly | NoUpdate}, { LFUN_PRIORSEL, "screen-up-select", ReadOnly }, { LFUN_SCROLL_INSET, "inset-scroll", ReadOnly }, - { LFUN_SELFINSERT, "self-insert", Noop }, + { LFUN_SELFINSERT, "self-insert", SingleParUpdate }, { LFUN_SPACE_INSERT, "space-insert", Noop }, { LFUN_CHARATCURSOR, "server-char-after", ReadOnly }, { LFUN_GETFONT, "server-get-font", ReadOnly }, diff --git a/src/LyXAction.h b/src/LyXAction.h index f5766e23c9..4d66c0f76b 100644 --- a/src/LyXAction.h +++ b/src/LyXAction.h @@ -51,7 +51,8 @@ public: ReadOnly = 1, //< can be used in RO mode (perhaps this should change) NoBuffer = 2, //< Can be used when there is no document open Argument = 4, //< Requires argument - NoUpdate = 8 //< Does not (usually) require update + NoUpdate = 8, //< Does not (usually) require update + SingleParUpdate = 16 //< Usually only requires this par updated }; LyXAction(); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 59a10696ba..0ceab6d4a9 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2005-10-07 Martin Vermeer + + * QContentPane.C (QContentPane): make times 50 msec instead of 25, + will consume less CPU (Thanks Angus profiling) + 2005-10-06 Jürgen Spitzmüller * QCitationDialog.C (openFind): ensure the main citation dialog diff --git a/src/frontends/qt2/QContentPane.C b/src/frontends/qt2/QContentPane.C index 1731af6c6d..526c62599f 100644 --- a/src/frontends/qt2/QContentPane.C +++ b/src/frontends/qt2/QContentPane.C @@ -104,7 +104,7 @@ QContentPane::QContentPane(QWorkArea * parent) this, SLOT(scrollBarChanged(int))); // Start the timer, one-shot. - step_timer_.start(25, true); + step_timer_.start(50, true); } diff --git a/src/rowpainter.C b/src/rowpainter.C index 907a3c220e..d06e7e2939 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -769,30 +769,30 @@ void paintText(BufferView const & bv, ViewMetricsInfo const & vi) yy += text->getPar(pit).descent(); } - - // paint one paragraph above and one below + // Cache one paragraph above and one below // Note MV: this cannot be suppressed even for singlepar. // Try viewing the User Guide Mobius figure + if (vi.p1 > 0) { text->redoParagraph(vi.p1 - 1); - paintPar(pi, *bv.text(), vi.p1 - 1, 0, - vi.y1 - text->getPar(vi.p1 - 1).descent()); + theCoords.parPos()[bv.text()][vi.p1 - 1] = + Point(0, vi.y1 - text->getPar(vi.p1 - 1).descent()); } if (vi.p2 < lyx::pit_type(text->paragraphs().size()) - 1) { text->redoParagraph(vi.p2 + 1); - paintPar(pi, *bv.text(), vi.p2 + 1, 0, - vi.y2 + text->getPar(vi.p2 + 1).ascent()); + theCoords.parPos()[bv.text()][vi.p2 + 1] = + Point(0, vi.y2 + text->getPar(vi.p2 + 1).ascent()); } // and grey out above (should not happen later) // lyxerr << "par ascent: " << text->getPar(vi.p1).ascent() << endl; - if (vi.y1 > 0) + if (vi.y1 > 0 && !vi.singlepar) pain.fillRectangle(0, 0, bv.workWidth(), vi.y1, LColor::bottomarea); // and possibly grey out below // lyxerr << "par descent: " << text->getPar(vi.p1).ascent() << endl; - if (vi.y2 < bv.workHeight()) + if (vi.y2 < bv.workHeight() && !vi.singlepar) pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - vi.y2, LColor::bottomarea); } diff --git a/src/text3.C b/src/text3.C index 5718a20136..2a7b879f3f 100644 --- a/src/text3.C +++ b/src/text3.C @@ -294,7 +294,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) CursorSlice oldTopSlice = cur.top(); bool oldBoundary = cur.boundary(); bool sel = cur.selection(); - bool needsUpdate = !lyxaction.funcHasFlag(cmd.action, LyXAction::NoUpdate); + // Signals that, even if needsUpdate == false, an update of the + // cursor paragraph is required + bool singleParUpdate = lyxaction.funcHasFlag(cmd.action, + LyXAction::SingleParUpdate); + // Signals that a full-screen update is required + bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action, + LyXAction::NoUpdate) || singleParUpdate); + // Remember the old paragraph metric + Dimension olddim = cur.paragraph().dim(); switch (cmd.action) { @@ -1125,13 +1133,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cur.resetAnchor(); moveCursor(cur, false); - - needsUpdate = redoParagraph(cur.pit()); - if (!needsUpdate) { - // update only this paragraph - cur.bv().update(Update::SinglePar | Update::Force); - } - bv->updateScrollbar(); break; } @@ -1528,6 +1529,14 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) break; } + if (singleParUpdate) + // Inserting characters does not change par height + if (cur.paragraph().dim().asc == olddim.asc + && cur.paragraph().dim().des == olddim.des) { + // if so, update _only_ this paragraph + cur.bv().update(Update::SinglePar | Update::Force); + } else + needsUpdate = true; if (!needsUpdate && &oldTopSlice.inset() == &cur.inset() && oldTopSlice.idx() == cur.idx()