It turns out...

    123                 InsetBase & inset = cursor[0].inset();
    124 
    125                 DocIterator it = doc_iterator_begin(inset);
    126                 DocIterator const et = doc_iterator_end(inset);
    127 

    ...

    131                 for ( ; it != et; it.forwardPos()) {

-----------------------------------------------
                1.77   12.30      12/12          LCursor::goUpDown(bool) [2]
[3]      3.8    1.77   12.30      12         (anonymous 
namespace)::bruteFind(LCursor&, int, int, int, int, int, int) [3]
                2.75    8.99 2175504/2554681     DocIterator::forwardPos() [4]
                0.54    0.00 2175504/2175875     LCursor::bv() const [132]
                0.01    0.00      12/20          doc_iterator_end(InsetBase&) 
[717]
                0.00    0.00      12/20          doc_iterator_begin(InsetBase&) 
[1730]
                0.00    0.00      12/13          LCursor::setCursor(DocIterator 
const&) [1877]
-----------------------------------------------

...that the method bruteFind() in cursor.C searches the *whole
document*, i.e., *every single character position*, for the best place
to drop the cursor!

This causes a noticeable slowness (several seconds!) when exiting some
formulas in the User Guide.

How to make it faster? The attached doesn't really help much, because
forwardPar() still calls forwardPos() internally for every character.

- Martin

Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.141
diff -u -p -r1.141 cursor.C
--- cursor.C	11 Jan 2006 17:08:50 -0000	1.141
+++ cursor.C	13 Jan 2006 16:30:23 -0000
@@ -135,6 +135,11 @@ namespace {
 				Point p = bv_funcs::getPos(it, false);
 				int xo = p.x_;
 				int yo = p.y_;
+				// See if jumping a whole par is OK:
+				DocIterator test = it;
+				test.forwardPar();
+				if (bv_funcs::getPos(test, false).y_ < ylow)
+					it = test;
 				if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
 					double const dx = xo - x;
 					double const dy = yo - y;
@@ -147,6 +152,9 @@ namespace {
 						best_cursor = it;
 					}
 				}
+				// Jump out when well past:
+				if (yo > yhigh)
+					break;
 			}
 		}
 

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

Reply via email to