khtml - render_text: Q3PtrVector->QVector

Peter Kümmel syntheticpp at gmx.net
Fri Jun 30 08:49:12 BST 2006


Maks Orlovich wrote:
> On Tuesday 27 June 2006 16: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? 
> 
> This patch is wrong. Q3PtrVector has very different semantics from QVector in 
> many functions, in particular count()/size() and insert() (which in 
> QPtrVector behaves more like replace).
> 
> 
> 

OK. I've found the usage of this Q3PtrVector functions:

in render_.text:

count()
isEmpty()
size()
resize()
at()
[]()

insert()
m_lines.insert(m_lines.count(), s);

remove()
       unsigned int len = m_lines.size();
       for(unsigned int i=0; i < len; i++) {
            m_lines.remove(i);

in khtml_part:
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()) {


And this is what Q3PtrVector does:

insert()
(autodelete is disabled in the code)
insert replaces the index position
increment the counter for the positions != 0

bool Q3GVector::insert( uint index, Item d )	// insert item at index
{
    if ( vec[index] ) {				// remove old item
	numItems--;
    }
    if ( d ) {
	vec[index] = newItem( d );  // ::newItem(Item d){return d;}
	numItems++;
	return vec[index] != 0;
    } else {
	vec[index] = 0;				// reset item
    }
    return true;
}


remove()
(autodelete is disabled in the code)
decrement the counter for the positions != 0

bool Q3GVector::remove( uint index )		// remove item at index
{
    if ( vec[index] ) {				// valid item
	vec[index] = 0;				// reset pointer
	numItems--;
    }
    return true;
}

at(), []():
Item	at( uint index ) const		// return indexed item
{
    return vec[index];
}

count():
number of array positions != 0

isEmpty():
count() == 0

size():
size of the allocated array

resize():
resizes the array without deleting the items
(autodelete is disabled in the code)



So only an insert at the end of a full array
and a setting to 0 off the whole array happens.

I don't see that the code makes usage of the Q3PtrVector feature that
inserting null pointers dont't increase the counter, there is only
one line where insert is used and it inserts a valid pointer:

    KHTMLAssert(box->isInlineTextBox());
    InlineTextBox *s = static_cast<InlineTextBox *>(box);
    m_lines.insert(m_lines.count(), s);


So, what do you think about this mapping?

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

loop with
remove()        clear()



Peter





More information about the kde-core-devel mailing list