[Scummvm-cvs-logs] SF.net SVN: scummvm:[34747] scummvm/branches/gsoc2008-gui/common

tanoku at users.sourceforge.net tanoku at users.sourceforge.net
Sun Oct 5 12:19:09 CEST 2008


Revision: 34747
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34747&view=rev
Author:   tanoku
Date:     2008-10-05 10:19:09 +0000 (Sun, 05 Oct 2008)

Log Message:
-----------
Added a fixed memory pool for XML Node allocation, as suggested by Max.

Modified Paths:
--------------
    scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
    scummvm/branches/gsoc2008-gui/common/xmlparser.h

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-10-04 21:40:14 UTC (rev 34746)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-10-05 10:19:09 UTC (rev 34747)
@@ -188,7 +188,7 @@
 	if (ignore == false)
 		result = closedKeyCallback(_activeKey.top());
 		
-	delete _activeKey.pop();
+	freeNode(_activeKey.pop());
 	
 	return result;
 }
@@ -202,7 +202,7 @@
 		buildLayout();
 
 	while (!_activeKey.empty())
-		delete _activeKey.pop();
+		freeNode(_activeKey.pop());
 
 	cleanup();
 
@@ -253,7 +253,7 @@
 						break;
 					}
 				} else {
-					ParserNode *node = new ParserNode;
+					ParserNode *node = allocNode(); //new ParserNode;
 					node->name = _token;
 					node->ignore = false;
 					node->depth = _activeKey.size();

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-10-04 21:40:14 UTC (rev 34746)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-10-05 10:19:09 UTC (rev 34747)
@@ -47,6 +47,8 @@
 	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 @@
 
 	virtual ~XMLParser() {
 		while (!_activeKey.empty())
-			delete _activeKey.pop();
+			freeNode(_activeKey.pop());
 
 		delete _XMLkeys;
 		delete _stream;
@@ -166,7 +168,19 @@
 		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.
 	 * Used for the loading of Theme Description files


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list