summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-06-24 09:15:45 +0000
committersmatz <smatz@openttd.org>2008-06-24 09:15:45 +0000
commit96d880ea9e91f9c9bdbc2a25918122ad382be97c (patch)
tree434b9d9480c094ea3ab6aebd08d1b5005f4bcc1e /src
parent40d5242f919824f37d533360af8d7ab6ad0b4722 (diff)
downloadopenttd-96d880ea9e91f9c9bdbc2a25918122ad382be97c.tar.xz
(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
Diffstat (limited to 'src')
-rw-r--r--src/blitter/factory.hpp15
-rw-r--r--src/driver.cpp15
-rw-r--r--src/driver.h13
3 files changed, 33 insertions, 10 deletions
diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp
index 928b78547..b33c9e5a9 100644
--- a/src/blitter/factory.hpp
+++ b/src/blitter/factory.hpp
@@ -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 @@ public:
if (this->name == NULL) return;
GetBlitters().erase(this->name);
if (GetBlitters().empty()) delete &GetBlitters();
- free(this->name);
+ free((void *)this->name);
}
/**
diff --git a/src/driver.cpp b/src/driver.cpp
index 63e76cffa..b042ea620 100644
--- a/src/driver.cpp
+++ b/src/driver.cpp
@@ -156,7 +156,9 @@ void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int
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 @@ DriverFactoryBase::~DriverFactoryBase() {
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);
}
diff --git a/src/driver.h b/src/driver.h
index af98e0fa5..e4d9e4627 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -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 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type);
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()
{