diff options
author | Vicent Marti | 2008-10-05 10:19:09 +0000 |
---|---|---|
committer | Vicent Marti | 2008-10-05 10:19:09 +0000 |
commit | e32fc0ccca2570fc560969507351cf99a304ebf4 (patch) | |
tree | ccdc9d089daa997aab74d28591118ecb0231f5e2 /common | |
parent | 1380e4f7e70e712ad7984c5b5e8b070ab954987c (diff) | |
download | scummvm-rg350-e32fc0ccca2570fc560969507351cf99a304ebf4.tar.gz scummvm-rg350-e32fc0ccca2570fc560969507351cf99a304ebf4.tar.bz2 scummvm-rg350-e32fc0ccca2570fc560969507351cf99a304ebf4.zip |
Added a fixed memory pool for XML Node allocation, as suggested by Max.
svn-id: r34747
Diffstat (limited to 'common')
-rw-r--r-- | common/xmlparser.cpp | 6 | ||||
-rw-r--r-- | common/xmlparser.h | 16 |
2 files changed, 18 insertions, 4 deletions
diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 6c1aa7d0e4..44274f7c8d 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -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(); diff --git a/common/xmlparser.h b/common/xmlparser.h index 4b76278d47..ad9ad799f0 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -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. |