[Scummvm-cvs-logs] SF.net SVN: scummvm: [22841] scummvm/trunk/gui

sev at users.sourceforge.net sev at users.sourceforge.net
Fri Jun 2 19:52:02 CEST 2006


Revision: 22841
Author:   sev
Date:     2006-06-02 10:51:20 -0700 (Fri, 02 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=22841&view=rev

Log Message:
-----------
Turn AliasesMap and VariablesMap keys from String to const char *.
Stats before:
Strings: 12048
mallocs: 55629
after:
Strings: 6370
mallocs: 42117
Here Strings are non-empty strings. Mallocs are string-related mallocs
including mallocs in HashMap BaseNode.

Modified Paths:
--------------
    scummvm/trunk/gui/eval.cpp
    scummvm/trunk/gui/eval.h
    scummvm/trunk/gui/theme-config.cpp
Modified: scummvm/trunk/gui/eval.cpp
===================================================================
--- scummvm/trunk/gui/eval.cpp	2006-06-02 16:07:40 UTC (rev 22840)
+++ scummvm/trunk/gui/eval.cpp	2006-06-02 17:51:20 UTC (rev 22841)
@@ -288,11 +288,11 @@
 	if (val != EVAL_UNDEF_VAR)
 		return val;
 
-	String var = String(s);
+	const char *var = s;
 	if (includeAliases) {
-		AliasesMap::const_iterator itera = _aliases.find(var);
+		AliasesMap::const_iterator itera = _aliases.find(s);
 		if (itera != _aliases.end())
-			var = itera->_value;
+			var = itera->_value.c_str();
 	}
 
 	VariablesMap::const_iterator iterv = _vars.find(var);
@@ -302,16 +302,12 @@
 	return EVAL_UNDEF_VAR;
 }
 
-void Eval::setAlias(const String &section, const String name, const String value) {
-	String var = String(&(name.c_str()[4]));
-
-	_aliases[var] = value;
+void Eval::setAlias(const String &section, const char *name, const String value) {
+	_aliases[name + 4] = value;
 }
 
-void Eval::setVar(const String &section, const String name, const String value) {
-	String var = String(&(name.c_str()[4]));
-
-	_vars[var] = eval(value, section, name, 0);
+void Eval::setVar(const String &section, const char *name, const String value) {
+	_vars[name + 4] = eval(value, section, name, 0);
 }
 
 void Eval::reset() {

Modified: scummvm/trunk/gui/eval.h
===================================================================
--- scummvm/trunk/gui/eval.h	2006-06-02 16:07:40 UTC (rev 22840)
+++ scummvm/trunk/gui/eval.h	2006-06-02 17:51:20 UTC (rev 22841)
@@ -55,13 +55,13 @@
 	~Eval();
 
 	int eval(const String &input, const String &section, const String &name, int startpos);
-	void setAlias(const String &section, const String name, const String value);
-	void setVar(const String &section, const String name, const String value);
+	void setAlias(const String &section, const char *name, const String value);
+	void setVar(const String &section, const char *name, const String value);
 
 	void setParent(const String name);
 
-	void setVar(const String name, int val) { _vars[name] = val; }
-	void setAlias(const String name, const String val) { _aliases[name] = val; }
+	void setVar(const char *name, int val) { _vars[name] = val; }
+	void setAlias(const char *name, const String val) { _aliases[name] = val; }
 
 	int getVar(String s) { return getVar_(s.c_str()); }
 	int getVar(String s, int def) {
@@ -73,9 +73,14 @@
 
 	void reset();
 
-	typedef HashMap<String, int> VariablesMap;
-	typedef HashMap<String, String> AliasesMap;
+	struct CharStar_EqualTo {
+		bool operator()(const char *x, const char *y) const { return strcmp(x, y) == 0; }
+	};
 
+	//typedef HashMap<String, int> VariablesMap;
+	typedef HashMap<const char *, int, Common::Hash<const char *>, CharStar_EqualTo> VariablesMap;
+	typedef HashMap<const char *, String, Common::Hash<const char *>, CharStar_EqualTo> AliasesMap;
+
 private:
 	void getToken();
 	void level2(int *);

Modified: scummvm/trunk/gui/theme-config.cpp
===================================================================
--- scummvm/trunk/gui/theme-config.cpp	2006-06-02 16:07:40 UTC (rev 22840)
+++ scummvm/trunk/gui/theme-config.cpp	2006-06-02 17:51:20 UTC (rev 22841)
@@ -424,13 +424,13 @@
 		to += postfixes[i];
 
 		_evaluator->setAlias(selfpostfixes[i], to);
-		_evaluator->setVar(to, EVAL_UNDEF_VAR);
+		_evaluator->setVar(to.c_str(), EVAL_UNDEF_VAR);
 	}
 
 	for (i = 0; i < str.size(); i++) {
 		if (isspace(str[i]) && level == 0) {
 			value = _evaluator->eval(String(&(str.c_str()[start]), i - start), section, name + postfixes[npostfix], start);
-			_evaluator->setVar(prefixedname + postfixes[npostfix++], value);
+			_evaluator->setVar((prefixedname + postfixes[npostfix++]).c_str(), value);
 			start = i + 1;
 		}
 		if (str[i] == '(')
@@ -453,15 +453,15 @@
 
 	// process VAR=VALUE construct
 	if (npostfix == 0)
-		_evaluator->setVar(name, value);
+		_evaluator->setVar(name.c_str(), value);
 	else
-		_evaluator->setVar(prefixedname + postfixes[npostfix], value);
+		_evaluator->setVar((prefixedname + postfixes[npostfix]).c_str(), value);
 
 	// If we have all 4 parameters, set .x2 and .y2
 	if (npostfix == 3) {
-		_evaluator->setVar(prefixedname + ".x2", 
+		_evaluator->setVar((prefixedname + ".x2").c_str(), 
 			_evaluator->getVar(prefixedname + ".x") + _evaluator->getVar(prefixedname + ".w"));
-		_evaluator->setVar(prefixedname + ".y2", 
+		_evaluator->setVar((prefixedname + ".y2").c_str(), 
 			_evaluator->getVar(prefixedname + ".y") + _evaluator->getVar(prefixedname + ".h"));
 	}
 
@@ -482,12 +482,12 @@
 			continue;
 		}
 		if (iterk->key.hasPrefix("set_")) {
-			_evaluator->setAlias(name, iterk->key, prefix + iterk->value);
+			_evaluator->setAlias(name, iterk->key.c_str(), prefix + iterk->value);
 			continue;
 		}
 		if (iterk->key.hasPrefix("def_")) {
 			if (!skipDefs)
-				_evaluator->setVar(name, prefix + iterk->key, iterk->value);
+				_evaluator->setVar(name, (prefix + iterk->key).c_str(), iterk->value);
 			continue;
 		}
 		if (iterk->key == "use") {
@@ -529,16 +529,16 @@
 }
 
 void Theme::setSpecialAlias(const String alias, const String &name) {
-	const char *postfixes[] = {"x", "y", "w", "h", "x2", "y2"};
+	const char *postfixes[] = {".x", ".y", ".w", ".h", ".x2", ".y2"};
 	int i;
 
 	for (i = 0; i < ARRAYSIZE(postfixes); i++) {
 		String from, to;
 
-		from = alias + "." + postfixes[i];
-		to = name + "." + postfixes[i];
+		from = alias + postfixes[i];
+		to = name + postfixes[i];
 
-		_evaluator->setAlias(from, to);
+		_evaluator->setAlias(from.c_str(), to);
 	}
 }
 


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