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

tanoku at users.sourceforge.net tanoku at users.sourceforge.net
Mon Sep 29 12:27:18 CEST 2008


Revision: 34677
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34677&view=rev
Author:   tanoku
Date:     2008-09-29 10:27:16 +0000 (Mon, 29 Sep 2008)

Log Message:
-----------
Reduced memory usage by closing theme files after parsing. Could make things a tad slower.

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

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-09-28 22:19:11 UTC (rev 34676)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.cpp	2008-09-29 10:27:16 UTC (rev 34677)
@@ -43,7 +43,7 @@
 	int lineStart = 0;
 
 	if (_fileName == "Memory Stream") {
-		lineStart = MAX(0, _pos - 35);
+		lineStart = MAX(0, original_pos - 35);
 		lineCount = 0;
 	} else {
 		do {
@@ -51,7 +51,7 @@
 				lineCount++;
 		
 				if (lineStart == 0)
-					lineStart = MAX(pos + 1, _pos - 60);
+					lineStart = MAX(pos + 1, original_pos - 60);
 			}
 			
 			_stream->seek(-1, SEEK_CUR);
@@ -210,7 +210,6 @@
 	bool selfClosure = false;
 
 	_state = kParserNeedKey;
-	_pos = 0;
 	_activeKey.clear();
 
 	_char = _stream->readByte();

Modified: scummvm/branches/gsoc2008-gui/common/xmlparser.h
===================================================================
--- scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-09-28 22:19:11 UTC (rev 34676)
+++ scummvm/branches/gsoc2008-gui/common/xmlparser.h	2008-09-29 10:27:16 UTC (rev 34677)
@@ -222,6 +222,13 @@
 		_fileName = "Compressed File Stream";
 		return true;
 	}
+	
+	void close() {
+		if (_stream) {
+			delete _stream;
+			_stream = 0;
+		}
+	}
 
 	/**
 	 * The actual parsing function.
@@ -361,7 +368,7 @@
 					break;
 
 				if (_char == 0)
-					parserError("Comment has no closure.");
+					return parserError("Comment has no closure.");
 			}
 			_char = _stream->readByte();
 			return true;
@@ -449,7 +456,6 @@
 	Common::List<XMLKeyLayout*> _layoutList;
 
 private:
-	int _pos; /** Current position on the XML buffer. */
 	char _char;
 	SeekableReadStream *_stream;
 	Common::String _fileName;

Modified: scummvm/branches/gsoc2008-gui/gui/ThemeEngine.cpp
===================================================================
--- scummvm/branches/gsoc2008-gui/gui/ThemeEngine.cpp	2008-09-28 22:19:11 UTC (rev 34676)
+++ scummvm/branches/gsoc2008-gui/gui/ThemeEngine.cpp	2008-09-29 10:27:16 UTC (rev 34677)
@@ -501,6 +501,7 @@
 	// file inside the themes directory.
 	// Use the Python script "makedeftheme.py" to convert a normal XML theme
 	// into the "default.inc" file, which is ready to be included in the code.
+	bool result;
 
 #ifdef GUI_ENABLE_BUILTIN_THEME
 	const char *defaultXML =
@@ -513,7 +514,10 @@
 	_themeName = "ScummVM Classic Theme (Builtin Version)";
 	_themeFileName = "builtin";
 
-	return parser()->parse();
+	result = parser()->parse();
+	parser()->close();
+	
+	return result;
 #else
 	warning("The built-in theme is not enabled in the current build. Please load an external theme");
 	return false;
@@ -527,6 +531,7 @@
 	char fileNameBuffer[32];
 	Common::String stxHeader;
 	int parseCount = 0;
+	bool failed = false;
 	
 #ifdef USE_ZLIB
 	unzFile zipFile = unzOpen((themeName).c_str());
@@ -550,19 +555,25 @@
 
 					if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {
 						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
-						return false;
+						failed = true;
 					}
 						
 					delete stream;
 					
-				} else {
+				} else if (!failed) {
 					parseCount++;
 					
-					if (parser()->loadStream(stream) == false || parser()->parse() == false) {
+					if (parser()->loadStream(stream) == false) {
 						warning("Failed to load stream for zipped file '%s'", fileNameBuffer);
-						unzClose(zipFile);
-						return false;
+						failed = true;
 					}
+					
+					if (parser()->parse() == false) {
+						warning("Theme parsing failed on zipped file '%s'.", fileNameBuffer);
+						failed = true;
+					}
+					
+					parser()->close();
 				}
 			} 
 		
@@ -581,13 +592,20 @@
 				return false;
 			
 			for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) {
-				if (i->getName().hasSuffix(".stx")) {
+				if (!failed && i->getName().hasSuffix(".stx")) {
 					parseCount++;
 					
-					if (parser()->loadFile(*i) == false || parser()->parse() == false) {
+					if (parser()->loadFile(*i) == false) {
+						warning("Failed to load STX file '%s'", i->getName().c_str());
+						failed = true;
+					}
+					
+					if (parser()->parse() == false) {
 						warning("Failed to parse STX file '%s'", i->getName().c_str());
-						return false;
+						failed = true;
 					}
+					
+					parser()->close();
 				} else if (i->getName() == "THEMERC") {
 					Common::File f;
 					f.open(*i);
@@ -595,7 +613,7 @@
 
 					if (!themeConfigParseHeader(stxHeader.c_str(), _themeName)) {
 						warning("Corrupted 'THEMERC' file in theme '%s'", _themeFileName.c_str());
-						return false;
+						failed = true;
 					}
 				}
 			}
@@ -608,7 +626,7 @@
 #endif
 
 
-	return (parseCount > 0 && _themeName.empty() == false);
+	return (parseCount > 0 && _themeName.empty() == false && failed == false);
 }
 
 


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