khtml - render_text: Q3PtrVector->QVector

Peter K├╝mmel syntheticpp at gmx.net
Wed Jul 5 14:23:58 BST 2006


SVN commit 558475 by kuemmel:

Get rid of Q3PtrVector container for the inline text boxes.

Q3PtrVector  -> QVector
------------------------
count()         count()==size()
size()          capacity()
isEmpty()       isEmpty()
resize()        reserve()
at()            at()
[]()            []()
insert()        replace()

loop with
remove()        clear()

CCMAIL:mo85 at cornell.edu
CCMAIL:khtml-devel at kde.org
CCMAIL:kde-core-devel at kde.org



 M  +5 -5      khtml_part.cpp
 M  +20 -32    rendering/render_text.cpp
 M  +13 -16    rendering/render_text.h


--- trunk/KDE/kdelibs/khtml/khtml_part.cpp #558474:558475
@@ -5959,9 +5959,9 @@
     for (khtml::RenderObject *n = renderNode; n; n = n->nextSibling()) {
         if (n->isText()) {
             khtml::RenderText* const textRenderer =
static_cast<khtml::RenderText *>(n);
-            const khtml::InlineTextBoxArray &runs =
textRenderer->inlineTextBoxes();
-	    const unsigned lim = runs.count();
-            for (unsigned i = 0; i != lim; ++i) {
+            const khtml::RenderText::InlineTextBoxVector &runs =
textRenderer->inlineTextBoxes();
+            const int lim = runs.count();
+            for (int i = 0; i != lim; ++i) {
                 if (runs[i]->m_y == y && textRenderer->element()) {
                     startNode = textRenderer->element();
                     startOffset = runs[i]->m_start;
@@ -6001,8 +6001,8 @@

         if (n->isText()) {
             khtml::RenderText* const textRenderer =
static_cast<khtml::RenderText *>(n);
-            const khtml::InlineTextBoxArray &runs =
textRenderer->inlineTextBoxes();
-            for (int i = (int)runs.count()-1; i >= 0; --i) {
+            const khtml::RenderText::InlineTextBoxVector &runs =
textRenderer->inlineTextBoxes();
+            for (int i = runs.count()-1; i >= 0; --i) {
                 if (runs[i]->m_y == y && textRenderer->element()) {
                     endNode = textRenderer->element();
                     endOffset = runs[i]->m_start + runs[i]->m_len;
--- trunk/KDE/kdelibs/khtml/rendering/render_text.cpp #558474:558475
@@ -485,23 +485,10 @@

 //
-----------------------------------------------------------------------------

-InlineTextBoxArray::InlineTextBoxArray()
-{
-    setAutoDelete(false);
-}
-
-int InlineTextBoxArray::compareItems( Item d1, Item d2 )
-{
-    assert(d1);
-    assert(d2);
-
-    return static_cast<InlineTextBox*>(d1)->m_y -
static_cast<InlineTextBox*>(d2)->m_y;
-}
-
 // remove this once QVector::bsearch is fixed
-int InlineTextBoxArray::findFirstMatching(Item d) const
+int RenderText::findFirstMatching(InlineTextBoxVector* tboxes, InlineTextBox*
d)
 {
-    int len = count();
+    int len = tboxes->count();

     if ( !len )
 	return -1;
@@ -514,10 +501,10 @@
     while ( n1 <= n2 ) {
 	int  res;
 	mid = (n1 + n2)/2;
-	if ( (*this)[mid] == 0 )			// null item greater
+	if ( (*tboxes)[mid] == 0 )			// null item greater
 	    res = -1;
 	else
-	    res = ((Q3GVector*)this)->compareItems( d, (*this)[mid] );
+	    res = d != (*tboxes)[mid] ;
 	if ( res < 0 )
 	    n2 = mid - 1;
 	else if ( res > 0 )
@@ -530,12 +517,11 @@
     /* if ( !found )
 	return -1; */
     // search to first one equal or bigger
-    while ( found && (mid > 0) && !((Q3GVector*)this)->compareItems(d,
(*this)[mid-1]) )
+    while ( found && (mid > 0) && !( d != (*tboxes)[mid-1]) )
 	mid--;
     return mid;
 }

-//
-------------------------------------------------------------------------------------

 RenderText::RenderText(DOM::NodeImpl* node, DOMStringImpl *_str)
     : RenderObject(node)
@@ -585,20 +571,19 @@

 void RenderText::deleteInlineBoxes(RenderArena* arena)
 {
-    // this is a slight variant of QArray::clear().
     // We don't delete the array itself here because its
     // likely to be used in the same size later again, saves
-    // us resize() calls
-    unsigned int len = m_lines.size();
+    // us reserve() calls
+    int len = m_lines.capacity();
     if (len) {
         if (!arena)
             arena = renderArena();
-        for(unsigned int i=0; i < len; i++) {
+        for(int i = 0; i < len; i++) {
             InlineTextBox* s = m_lines.at(i);
             if (s)
                 s->detach(arena);
-            m_lines.remove(i);
         }
+        m_lines.clear();
     }

     KHTMLAssert(m_lines.count() == 0);
@@ -725,7 +710,7 @@
     int lastOffset = 0;
     FindSelectionResult lastResult = SelectionPointAfter;

-    for(unsigned int si = 0; si < m_lines.count(); si++)
+    for(int si = 0; si < m_lines.count(); si++)
     {
         InlineTextBox* s = m_lines[si];
         FindSelectionResult result;
@@ -890,7 +875,7 @@
     int ow = style()->outlineWidth();
     RenderStyle* pseudoStyle = hasFirstLine() ?
style()->getPseudoStyle(RenderStyle::FIRST_LINE) : 0;
     InlineTextBox f(0, pI.r.top()-ty);
-    int si = m_lines.findFirstMatching(&f);
+    int si = RenderText::findFirstMatching(&m_lines, &f);
     // something matching found, find the first one to paint
     bool isStatic = canvas()->staticMode();
     if (isStatic && pI.phase == PaintActionSelection) return;
@@ -1116,7 +1101,8 @@
     if (!m_lines.count())
 	return 0;
     int retval=6666666;
-    for (unsigned i=0;i < m_lines.count(); i++)
+    int lim = m_lines.count();
+    for (int i = 0; i < lim; i++)
     {
 	retval = qMin ( retval, int( m_lines[i]->m_x ));
     }
@@ -1231,10 +1217,10 @@
     s->m_reversed = reverse;
     //kDebug(6040) << "m_start: " << s->m_start << " m_len: " << s->m_len <<
endl;

-    if(m_lines.count() == m_lines.size())
-        m_lines.resize(m_lines.size()*2+1);
+    if(m_lines.count() == m_lines.capacity())
+        m_lines.reserve(m_lines.capacity()*2+1);

-    m_lines.insert(m_lines.count(), s);
+    m_lines.replace(m_lines.count(), s);
     //kDebug(6040) << this << " " << renderName() << "::position inserted" <<
endl;
 }

@@ -1267,7 +1253,8 @@
     int minx = 100000000;
     int maxx = 0;
     // slooow
-    for(unsigned int si = 0; si < m_lines.count(); si++) {
+    int lim = m_lines.count();
+    for(int si = 0; si < lim; si++) {
         InlineTextBox* s = m_lines[si];
         if(s->m_x < minx)
             minx = s->m_x;
@@ -1446,7 +1433,8 @@
 {
     RenderObject::dump( stream, ind );

-    for (unsigned int i = 0; i < m_lines.count(); i++) {
+    int lim = m_lines.count();
+    for (int i = 0; i < lim; i++) {
         stream << endl << ind << "   ";
         writeTextRun(stream, *this, *m_lines[i]);
     }
--- trunk/KDE/kdelibs/khtml/rendering/render_text.h #558474:558475
@@ -30,7 +30,7 @@
 #include "rendering/render_object.h"
 #include "rendering/render_line.h"

-#include <q3ptrvector.h>
+#include <qvector.h>
 #include <assert.h>

 class QPainter;
@@ -133,17 +133,6 @@
     friend class RenderText;
 };

-class InlineTextBoxArray : public Q3PtrVector<InlineTextBox>
-{
-public:
-    InlineTextBoxArray();
-
-    InlineTextBox* first();
-
-    int	  findFirstMatching( Item ) const;
-    virtual int compareItems( Item, Item );
-};
-
 class RenderText : public RenderObject
 {
     friend class InlineTextBox;
@@ -252,13 +241,21 @@
      */
     virtual long maxOffset() const;

+
+    /** container for the inline text boxes
+     */
+    typedef QVector<InlineTextBox*> InlineTextBoxVector;
+
     /** returns the number of inline text boxes
      */
     unsigned inlineTextBoxCount() const { return m_lines.count(); }
-    /** returns the array of inline text boxes for this render text.
+
+    /** returns the QVector of inline text boxes for this render text.
      */
-    const InlineTextBoxArray &inlineTextBoxes() const { return m_lines; }
+    const InlineTextBoxVector &inlineTextBoxes() const { return m_lines; }

+    static int findFirstMatching(InlineTextBoxVector* tboxes, InlineTextBox*
d);
+
 #ifdef ENABLE_DUMP
     virtual void dump(QTextStream &stream, const QString &ind) const;
 #endif
@@ -273,9 +270,9 @@
      */
     InlineTextBox * findInlineTextBox( int offset, int &pos,
     					bool checkFirstLetter = false );
-
+	
 protected: // members
-    InlineTextBoxArray m_lines;
+    InlineTextBoxVector m_lines;
     DOM::DOMStringImpl *str; //

     short m_lineHeight;




More information about the kde-core-devel mailing list