1
0
Fork 0

(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
release/0.7
smatz 2008-06-24 09:15:45 +00:00
parent fee2adb299
commit 61847389d6
3 changed files with 33 additions and 10 deletions

View File

@ -8,7 +8,6 @@
#include "base.hpp" #include "base.hpp"
#include "../debug.h" #include "../debug.h"
#include "../string_func.h" #include "../string_func.h"
#include <string>
#include <map> #include <map>
/** /**
@ -16,8 +15,16 @@
*/ */
class BlitterFactoryBase { class BlitterFactoryBase {
private: private:
char *name; const char *name;
typedef std::map<std::string, BlitterFactoryBase *> Blitters;
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() static Blitters &GetBlitters()
{ {
@ -58,7 +65,7 @@ public:
if (this->name == NULL) return; if (this->name == NULL) return;
GetBlitters().erase(this->name); GetBlitters().erase(this->name);
if (GetBlitters().empty()) delete &GetBlitters(); if (GetBlitters().empty()) delete &GetBlitters();
free(this->name); free((void *)this->name);
} }
/** /**

View File

@ -156,7 +156,9 @@ void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int
strecpy(buf, GetDriverTypeName(type), lastof(buf)); strecpy(buf, GetDriverTypeName(type), lastof(buf));
strecpy(buf + 5, name, 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); assert(P.second);
} }
@ -194,7 +196,14 @@ DriverFactoryBase::~DriverFactoryBase() {
strecpy(buf, GetDriverTypeName(type), lastof(buf)); strecpy(buf, GetDriverTypeName(type), lastof(buf));
strecpy(buf + 5, this->name, 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(); if (GetDrivers().empty()) delete &GetDrivers();
free(this->name); free((void *)this->name);
} }

View File

@ -8,7 +8,6 @@
#include "debug.h" #include "debug.h"
#include "core/enum_type.hpp" #include "core/enum_type.hpp"
#include "string_func.h" #include "string_func.h"
#include <string>
#include <map> #include <map>
bool GetDriverParamBool(const char * const *parm, const char *name); bool GetDriverParamBool(const char * const *parm, const char *name);
@ -37,9 +36,17 @@ DECLARE_POSTFIX_INCREMENT(Driver::Type);
class DriverFactoryBase { class DriverFactoryBase {
private: private:
Driver::Type type; Driver::Type type;
char *name; const char *name;
int priority; 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() static Drivers &GetDrivers()
{ {