From kde-core-devel Wed Jun 28 06:55:22 2006 From: =?ISO-8859-15?Q?Peter_K=FCmmel?= Date: Wed, 28 Jun 2006 06:55:22 +0000 To: kde-core-devel Subject: Re: khtml - render_text: Q3PtrVector->QVector Message-Id: <44A227DA.7040309 () gmx ! net> X-MARC-Message: https://marc.info/?l=kde-core-devel&m=115147766019656 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--------------030904080606070002000303" This is a multi-part message in MIME format. --------------030904080606070002000303 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit David Faure wrote: > On Tuesday 27 June 2006 22:29, Peter Kümmel wrote: >> I get a strange linker error when compiling >> khtml with msvc: it could not find Q3GVector::at, >> even though this function is an inline function. >> Maybe this is because of the debug mode, but trying >> to force the inlining doesn't work. >> >> Before fiddling around with this Q3Support code >> I've used QVector instead, which solves the linker >> error. >> >> Is it possible to apply the attached patch? The >> only point where I'm not sure is the replacement >> of the 'compareItems' function: > > You need to get rid of the QVector subclass and move the comparison > code to a static method which you then pass to qSort (third argument). > Which also means calling qSort from the code... > OK, I've removed the QVector and now InlineTextBoxArray is a typedef of RenderText: typedef QVector InlineTextBoxArray; Also findFirstMatching is now a (static) member of RenderText. But I don't understand where I should use qSort, in the old code int InlineTextBoxArray::compareItems( Item d1, Item d2 ) was never used because always the Q3GVector version is used: (Q3GVector*)this)->compareItems( d, (*this)[mid] ); and this function does only a != comparison. So I've dropped InlineTextBoxArray::compareItems Attached the new patch. Peter --------------030904080606070002000303 Content-Type: text/plain; name="qvector2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qvector2.diff" Index: khtml_part.cpp =================================================================== --- khtml_part.cpp (revision 555414) +++ khtml_part.cpp (working copy) @@ -5957,7 +5957,7 @@ for (khtml::RenderObject *n = renderNode; n; n = n->nextSibling()) { if (n->isText()) { khtml::RenderText* const textRenderer = static_cast(n); - const khtml::InlineTextBoxArray &runs = textRenderer->inlineTextBoxes(); + const khtml::RenderText::InlineTextBoxArray &runs = textRenderer->inlineTextBoxes(); const unsigned lim = runs.count(); for (unsigned i = 0; i != lim; ++i) { if (runs[i]->m_y == y && textRenderer->element()) { @@ -5999,7 +5999,7 @@ if (n->isText()) { khtml::RenderText* const textRenderer = static_cast(n); - const khtml::InlineTextBoxArray &runs = textRenderer->inlineTextBoxes(); + const khtml::RenderText::InlineTextBoxArray &runs = textRenderer->inlineTextBoxes(); for (int i = (int)runs.count()-1; i >= 0; --i) { if (runs[i]->m_y == y && textRenderer->element()) { endNode = textRenderer->element(); Index: rendering/render_text.h =================================================================== --- rendering/render_text.h (revision 555414) +++ rendering/render_text.h (working copy) @@ -30,7 +30,7 @@ #include "rendering/render_object.h" #include "rendering/render_line.h" -#include +#include #include class QPainter; @@ -133,17 +133,6 @@ friend class RenderText; }; -class InlineTextBoxArray : public Q3PtrVector -{ -public: - InlineTextBoxArray(); - - InlineTextBox* first(); - - int findFirstMatching( Item ) const; - virtual int compareItems( Item, Item ); -}; - class RenderText : public RenderObject { friend class InlineTextBox; @@ -255,10 +244,15 @@ /** returns the number of inline text boxes */ unsigned inlineTextBoxCount() const { return m_lines.count(); } + + typedef QVector InlineTextBoxArray; + /** returns the array of inline text boxes for this render text. */ const InlineTextBoxArray &inlineTextBoxes() const { return m_lines; } + static int findFirstMatching(InlineTextBoxArray* array, InlineTextBox* d); + #ifdef ENABLE_DUMP virtual void dump(QTextStream &stream, const QString &ind) const; #endif @@ -273,7 +267,7 @@ */ InlineTextBox * findInlineTextBox( int offset, int &pos, bool checkFirstLetter = false ); - + protected: // members InlineTextBoxArray m_lines; DOM::DOMStringImpl *str; // Index: rendering/render_text.cpp =================================================================== --- rendering/render_text.cpp (revision 555414) +++ rendering/render_text.cpp (working copy) @@ -485,23 +485,10 @@ // ----------------------------------------------------------------------------- -InlineTextBoxArray::InlineTextBoxArray() -{ - setAutoDelete(false); -} - -int InlineTextBoxArray::compareItems( Item d1, Item d2 ) -{ - assert(d1); - assert(d2); - - return static_cast(d1)->m_y - static_cast(d2)->m_y; -} - // remove this once QVector::bsearch is fixed -int InlineTextBoxArray::findFirstMatching(Item d) const +int RenderText::findFirstMatching(InlineTextBoxArray* array, InlineTextBox* d) { - int len = count(); + int len = array->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 ( (*array)[mid] == 0 ) // null item greater res = -1; else - res = ((Q3GVector*)this)->compareItems( d, (*this)[mid] ); + res = d != (*array)[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 != (*array)[mid-1]) ) mid--; return mid; } -// ------------------------------------------------------------------------------------- RenderText::RenderText(DOM::NodeImpl* node, DOMStringImpl *_str) : RenderObject(node) @@ -890,7 +876,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; --------------030904080606070002000303--