Extract and reuse nodes creation code
diff --git a/tinyxml2.h b/tinyxml2.h
index 034f002..8f2f487 100755
--- a/tinyxml2.h
+++ b/tinyxml2.h
@@ -1819,8 +1819,21 @@
static const char* _errorNames[XML_ERROR_COUNT];
void Parse();
+
+ template<class NodeType, int PoolElementSize>
+ NodeType* CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool );
};
+template<class NodeType, int PoolElementSize>
+inline NodeType* XMLDocument::CreateUnlinkedNode( MemPoolT<PoolElementSize>& pool )
+{
+ TIXMLASSERT( sizeof( NodeType ) == PoolElementSize );
+ TIXMLASSERT( sizeof( NodeType ) == pool.ItemSize() );
+ NodeType* returnNode = new (pool.Alloc()) NodeType( this );
+ TIXMLASSERT( returnNode );
+ returnNode->_memPool = &pool;
+ return returnNode;
+}
/**
A XMLHandle is a class that wraps a node pointer with null checks; this is