Merge pull request #500 from Dmitry-Me/reuseAttributeCreation

Reuse attribute creation code
This commit is contained in:
Lee Thomason 2016-11-25 22:05:34 -08:00 committed by GitHub
commit 5bbb6fb052
2 changed files with 14 additions and 8 deletions

View File

@ -1714,9 +1714,8 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
} }
} }
if ( !attrib ) { if ( !attrib ) {
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); attrib = CreateAttribute();
attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); TIXMLASSERT( attrib );
attrib->_memPool = &_document->_attributePool;
if ( last ) { if ( last ) {
last->_next = attrib; last->_next = attrib;
} }
@ -1724,7 +1723,6 @@ XMLAttribute* XMLElement::FindOrCreateAttribute( const char* name )
_rootAttribute = attrib; _rootAttribute = attrib;
} }
attrib->SetName( name ); attrib->SetName( name );
attrib->_memPool->SetTracked(); // always created and linked.
} }
return attrib; return attrib;
} }
@ -1764,10 +1762,8 @@ char* XMLElement::ParseAttributes( char* p )
// attribute. // attribute.
if (XMLUtil::IsNameStartChar( *p ) ) { if (XMLUtil::IsNameStartChar( *p ) ) {
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() ); XMLAttribute* attrib = CreateAttribute();
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute(); TIXMLASSERT( attrib );
attrib->_memPool = &_document->_attributePool;
attrib->_memPool->SetTracked();
p = attrib->ParseDeep( p, _document->ProcessEntities() ); p = attrib->ParseDeep( p, _document->ProcessEntities() );
if ( !p || Attribute( attrib->Name() ) ) { if ( !p || Attribute( attrib->Name() ) ) {
@ -1816,6 +1812,15 @@ void XMLElement::DeleteAttribute( XMLAttribute* attribute )
pool->Free( attribute ); pool->Free( attribute );
} }
XMLAttribute* XMLElement::CreateAttribute()
{
TIXMLASSERT( sizeof( XMLAttribute ) == _document->_attributePool.ItemSize() );
XMLAttribute* attrib = new (_document->_attributePool.Alloc() ) XMLAttribute();
attrib->_memPool = &_document->_attributePool;
attrib->_memPool->SetTracked();
return attrib;
}
// //
// <ele></ele> // <ele></ele>
// <ele>foo<b>bar</b></ele> // <ele>foo<b>bar</b></ele>

View File

@ -1563,6 +1563,7 @@ private:
//void LinkAttribute( XMLAttribute* attrib ); //void LinkAttribute( XMLAttribute* attrib );
char* ParseAttributes( char* p ); char* ParseAttributes( char* p );
static void DeleteAttribute( XMLAttribute* attribute ); static void DeleteAttribute( XMLAttribute* attribute );
XMLAttribute* CreateAttribute();
enum { BUF_SIZE = 200 }; enum { BUF_SIZE = 200 };
int _closingType; int _closingType;