mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 23:52:41 +00:00
Added a fixed memory pool for XML Node allocation, as suggested by Max.
svn-id: r34747
This commit is contained in:
parent
1380e4f7e7
commit
e32fc0ccca
@ -188,7 +188,7 @@ bool XMLParser::closeKey() {
|
||||
if (ignore == false)
|
||||
result = closedKeyCallback(_activeKey.top());
|
||||
|
||||
delete _activeKey.pop();
|
||||
freeNode(_activeKey.pop());
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -202,7 +202,7 @@ bool XMLParser::parse() {
|
||||
buildLayout();
|
||||
|
||||
while (!_activeKey.empty())
|
||||
delete _activeKey.pop();
|
||||
freeNode(_activeKey.pop());
|
||||
|
||||
cleanup();
|
||||
|
||||
@ -253,7 +253,7 @@ bool XMLParser::parse() {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ParserNode *node = new ParserNode;
|
||||
ParserNode *node = allocNode(); //new ParserNode;
|
||||
node->name = _token;
|
||||
node->ignore = false;
|
||||
node->depth = _activeKey.size();
|
||||
|
@ -47,6 +47,8 @@ namespace Common {
|
||||
External documentation available at:
|
||||
http://www.smartlikearoboc.com/scummvm_doc/xmlparser_doc.html
|
||||
*/
|
||||
|
||||
#define MAX_XML_DEPTH 8
|
||||
|
||||
#define XML_KEY(keyName) {\
|
||||
lay = new CustomXMLKeyLayout;\
|
||||
@ -112,7 +114,7 @@ public:
|
||||
|
||||
virtual ~XMLParser() {
|
||||
while (!_activeKey.empty())
|
||||
delete _activeKey.pop();
|
||||
freeNode(_activeKey.pop());
|
||||
|
||||
delete _XMLkeys;
|
||||
delete _stream;
|
||||
@ -166,6 +168,18 @@ public:
|
||||
int depth;
|
||||
XMLKeyLayout *layout;
|
||||
};
|
||||
|
||||
FixedSizeMemoryPool<sizeof(ParserNode), MAX_XML_DEPTH> _nodePool;
|
||||
|
||||
ParserNode *allocNode() {
|
||||
void* mem = _nodePool.malloc();
|
||||
return new (mem) ParserNode;
|
||||
}
|
||||
|
||||
void freeNode(ParserNode *node) {
|
||||
node->~ParserNode();
|
||||
_nodePool.free(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a file into the parser.
|
||||
|
Loading…
Reference in New Issue
Block a user