(svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
authorsmatz
Tue, 24 Jun 2008 09:15:45 +0000
changeset 11062 19abd15f7cf8
parent 11061 f5806d84e7a9
child 11064 7ebca843450b
(svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
Removes indirect dependency on <string> for 20 files, reduces binary size by 16kB
src/blitter/factory.hpp
src/driver.cpp
src/driver.h
--- a/src/blitter/factory.hpp	Tue Jun 24 09:05:24 2008 +0000
+++ b/src/blitter/factory.hpp	Tue Jun 24 09:15:45 2008 +0000
@@ -8,7 +8,6 @@
 #include "base.hpp"
 #include "../debug.h"
 #include "../string_func.h"
-#include <string>
 #include <map>
 
 /**
@@ -16,8 +15,16 @@
  */
 class BlitterFactoryBase {
 private:
-	char *name;
-	typedef std::map<std::string, BlitterFactoryBase *> Blitters;
+	const char *name;
+
+	struct StringCompare {
+		bool operator () (const char *a, const char *b) const
+		{
+			return strcmp(a, b) < 0;
+		}
+	};
+
+	typedef std::map<const char *, BlitterFactoryBase *, StringCompare> Blitters;
 
 	static Blitters &GetBlitters()
 	{
@@ -58,7 +65,7 @@
 		if (this->name == NULL) return;
 		GetBlitters().erase(this->name);
 		if (GetBlitters().empty()) delete &GetBlitters();
-		free(this->name);
+		free((void *)this->name);
 	}
 
 	/**
--- a/src/driver.cpp	Tue Jun 24 09:05:24 2008 +0000
+++ b/src/driver.cpp	Tue Jun 24 09:15:45 2008 +0000
@@ -156,7 +156,9 @@
 	strecpy(buf, GetDriverTypeName(type), lastof(buf));
 	strecpy(buf + 5, name, lastof(buf));
 
-	std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(buf, this));
+	const char *longname = strdup(buf);
+
+	std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(longname, this));
 	assert(P.second);
 }
 
@@ -194,7 +196,14 @@
 	strecpy(buf, GetDriverTypeName(type), lastof(buf));
 	strecpy(buf + 5, this->name, lastof(buf));
 
-	GetDrivers().erase(buf);
+	Drivers::iterator it = GetDrivers().find(buf);
+	assert(it != GetDrivers().end());
+
+	const char *longname = (*it).first;
+
+	GetDrivers().erase(it);
+	free((void *)longname);
+
 	if (GetDrivers().empty()) delete &GetDrivers();
-	free(this->name);
+	free((void *)this->name);
 }
--- a/src/driver.h	Tue Jun 24 09:05:24 2008 +0000
+++ b/src/driver.h	Tue Jun 24 09:15:45 2008 +0000
@@ -8,7 +8,6 @@
 #include "debug.h"
 #include "core/enum_type.hpp"
 #include "string_func.h"
-#include <string>
 #include <map>
 
 bool GetDriverParamBool(const char * const *parm, const char *name);
@@ -37,9 +36,17 @@
 class DriverFactoryBase {
 private:
 	Driver::Type type;
-	char *name;
+	const char *name;
 	int priority;
-	typedef std::map<std::string, DriverFactoryBase *> Drivers;
+
+	struct StringCompare {
+		bool operator () (const char *a, const char *b) const
+		{
+			return strcmp(a, b) < 0;
+		}
+	};
+
+	typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
 
 	static Drivers &GetDrivers()
 	{