Text Selection Speed

Koos Vriezen koos.vriezen at xs4all.nl
Fri Jun 21 12:42:53 BST 2002


On Fri, 14 Jun 2002, Koos Vriezen wrote:
> On Fri, 14 Jun 2002, Dirk Mueller wrote:
> > On Don, 13 Jun 2002, Matt Newell wrote:
> > > understanding to improve the horribly slow text selection algorithm.  I am
> > > starting to get a pretty decent understanding of how it works, but I still am
> > > not sure where all of the cpu cycles are going.  I just thought that you guys
> > > could give me a few pointers on what functions need optimizing, or how to
> > > profile khtml to find out for myself.
> >
> > There is no index about onscreen position -> rendertree object.
> >
> > Partially the text selection code simply scans through the tree for finding
> > the starting and end position, which is really slow. That part needs
> > rewriting, but up to now nobody volunteered.
>
> Also, if you uncomment kdDebug in KHTMLView::scheduleRepaint(x,y,w,h), you
> see that the whole visual khtml part is repainted while selecting text.

So, why don't do we a '

retrieving revision 1.107
diff -u -3 -p -r1.107 render_root.cpp
--- rendering/render_root.cpp   2002/03/27 13:30:20     1.107
+++ rendering/render_root.cpp   2002/06/21 11:25:36
@@ -277,9 +277,21 @@ void RenderRoot::setSelection(RenderObje

     // update selection status of all objects between m_selectionStart
and m_selectionEnd
     RenderObject* o = s;
+    int xs = o->xPos();
+    int xe = o->yPos();
+    int ys = o->xPos() + o->width();
+    int ye = o->yPos() + o->height();
     while (o && o!=e)
     {
         o->setSelectionState(SelectionInside);
+        if (o->xPos() < xs)
+            xs = o->xPos();
+        if (o->yPos() < ys)
+            xe = o->yPos();
+        if (xe < o->xPos() + o->width())
+            ys = o->xPos() + o->width();
+        if (ye < o->yPos() + o->height())
+            ye = o->yPos() + o->height();
 //      kdDebug( 6040 ) << "setting selected " << o << ", " << o->isText() << endl;
         RenderObject* no;
         if ( !(no = o->firstChild()) )
@@ -296,7 +308,7 @@ void RenderRoot::setSelection(RenderObje
     s->setSelectionState(SelectionStart);
     e->setSelectionState(SelectionEnd);
     if(s == e) s->setSelectionState(SelectionBoth);
-    repaint();
+    repaintRectangle(xs, ys, xe - xs, ye - ys, false);
 }

'? Still too much is repainted, but on a site like Slashdot, only about
one tenth of the visual part is repainted while selecting text with this
patch.


Koos






More information about the kfm-devel mailing list