On Sat, Jan 14, 2006 at 11:14:28AM +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> >> How to make it faster? The attached doesn't really help much,
> >> because forwardPar() still calls forwardPos() internally for every
> >> character.
> 
> Martin> The attached helps a lot, and is "low hanging fruit".
> 
> Did you look at forwardPar? I contains some optimization similar to
> what you do. So if yours is faster, I'd like to know what the
> difference is.
> 
> JMarc

You're so right... I overlooked that. Re-inventing the wheel.

In the attached I picked another low fruit too ;-)

- 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    14 Jan 2006 11:33:11 -0000
@@ -129,25 +129,36 @@ namespace {
                DocIterator best_cursor = et;
 
                for ( ; it != et; it.forwardPos()) {
+                       // Fast jumping by paragraph:
+                       if (bv_funcs::status(&cursor.bv(), it) 
+                           == bv_funcs::CUR_ABOVE)
+                           it.forwardPar();
+
                        // avoid invalid nesting when selecting
                        if (bv_funcs::status(&cursor.bv(), it) == 
bv_funcs::CUR_INSIDE
                            && (!cursor.selection() || positionable(it, 
cursor.anchor_))) {
                                Point p = bv_funcs::getPos(it, false);
                                int xo = p.x_;
                                int yo = p.y_;
-                               if (xlow <= xo && xo <= xhigh && ylow <= yo && 
yo <= yhigh) {
+                               if (ylow <= yo && yo <= yhigh 
+                                   && xlow <= xo && xo <= xhigh) {
                                        double const dx = xo - x;
                                        double const dy = yo - y;
                                        double const d = dx * dx + dy * dy;
                                        // '<=' in order to take the last 
possible position
                                        // this is important for clicking 
behind \sum in e.g. '\sum_i a'
                                        if (d <= best_dist) {
-                                               lyxerr << "*" << endl;
+                                               lyxerr << "*" << std::flush;
                                                best_dist   = d;
                                                best_cursor = it;
                                        }
                                }
+                               if (yo > yhigh)
+                                       break;
                        }
+                       // Play safe:
+                       if (bv_funcs::status(&cursor.bv(), it) == 
bv_funcs::CUR_BELOW)
+                               break;
                }
 
                if (best_cursor != et) {

Attachment: pgpoJuSUIPRgA.pgp
Description: PGP signature

Reply via email to