On Thu, 2005-09-22 at 03:26 +0300, Martin Vermeer wrote:

> I also noted that metrics is called twice for every keystroke. Surely one of
> those isn't necessary.
> 
> Sounds reasonable? Please test. Is it faster, or is it my imagination?

Here is a better patch, taking care of rowpainter too. metrics is still
called twice, but now (generally) only for the current paragraph, not
the whole screen. Ought to be faster. 

I saw no side effects.

- 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	22 Sep 2005 07:58:27 -0000
@@ -666,13 +666,16 @@ 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);
+		if (flags & Update::FitCursor) {
+			if (fitCursor()) {
+				forceupdate = true;
+				vi = metrics();
+			}
 		}
+
 		if (forceupdate) {
 			// Second drawing step
 			screen().redraw(*bv_, vi);
@@ -1340,7 +1343,9 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
 	// Redo paragraphs above cursor if necessary
 	int y1 = y0;
-	while (!singlepar && y1 > 0 && pit1 > 0) {
+	while (y1 > 0 && pit1 > 0) {
+	    	if (singlepar && (pit1 < cursor_.pit()))
+			break;
 		y1 -= text->getPar(pit1).ascent();
 		--pit1;
 		text->redoParagraph(pit1);
@@ -1364,7 +1369,9 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
 	// Redo paragraphs below cursor if necessary
 	int y2 = y0;
-	while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+	while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+	    	if (singlepar && (pit2 > cursor_.pit()))
+			break;
 		y2 += text->getPar(pit2).descent();
 		++pit2;
 		text->redoParagraph(pit2);
@@ -1386,6 +1393,7 @@ ViewMetricsInfo BufferView::Pimpl::metri
                 << BOOST_CURRENT_FUNCTION
                 << " y1: " << y1
                 << " y2: " << y2
+                << " 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	22 Sep 2005 07:58:28 -0000
@@ -1555,9 +1555,9 @@ void LyXFunc::dispatch(FuncRequest const
 			// This also initializes the position cache for all insets
 			// in (at least partially) visible top-level paragraphs.
 			if (update)
-				view()->update(Update::FitCursor | Update::Force);
+				view()->update(Update::FitCursor | Update::Force | Update::SinglePar);
 			else
-				view()->update(Update::FitCursor);
+				view()->update(Update::FitCursor | Update::SinglePar);
 
 			// if we executed a mutating lfun, mark the buffer as dirty
 			// FIXME: Why not use flag.enabled() but call getStatus again?
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.157
diff -u -p -r1.157 rowpainter.C
--- rowpainter.C	19 Sep 2005 11:18:20 -0000	1.157
+++ rowpainter.C	22 Sep 2005 07:58:28 -0000
@@ -787,12 +787,12 @@ void paintText(BufferView const & bv, Vi
 
 	// 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);
 }
 

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to