Remove CoreConfig use of memtables (bug 5899 part 1, r=fyren).

This commit is contained in:
David Anderson 2013-08-31 11:50:11 -07:00
parent 4500964394
commit a25f9010cc
3 changed files with 15 additions and 9 deletions

View File

@ -124,7 +124,7 @@ void CoreConfig::OnSourceModAllInitialized()
g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL);
} }
CoreConfig::CoreConfig() : m_Strings(512) CoreConfig::CoreConfig()
{ {
} }
@ -257,7 +257,6 @@ void CoreConfig::Initialize()
/* Reset cached key values */ /* Reset cached key values */
m_KeyValues.clear(); m_KeyValues.clear();
m_Strings.Reset();
/* Parse config file */ /* Parse config file */
if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay) if ((err=textparsers->ParseFile_SMC(filePath, this, NULL)) != SMCError_Okay)
@ -297,17 +296,18 @@ ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value,
pBase = pBase->m_pGlobalClassNext; pBase = pBase->m_pGlobalClassNext;
} }
m_KeyValues.replace(option, m_Strings.AddString(value)); ke::AString vstr(value);
m_KeyValues.replace(option, ke::Move(vstr));
return ConfigResult_Ignore; return ConfigResult_Ignore;
} }
const char *CoreConfig::GetCoreConfigValue(const char *key) const char *CoreConfig::GetCoreConfigValue(const char *key)
{ {
int address; StringHashMap<ke::AString>::Result r = m_KeyValues.find(key);
if (!m_KeyValues.retrieve(key, &address)) if (!r.found())
return NULL; return NULL;
return m_Strings.GetString(address); return r->value.chars();
} }
bool SM_AreConfigsExecuted() bool SM_AreConfigsExecuted()

View File

@ -35,8 +35,8 @@
#include "sm_globals.h" #include "sm_globals.h"
#include <ITextParsers.h> #include <ITextParsers.h>
#include <IRootConsoleMenu.h> #include <IRootConsoleMenu.h>
#include <am-string.h>
#include <sm_stringhashmap.h> #include <sm_stringhashmap.h>
#include "sm_memtable.h"
using namespace SourceMod; using namespace SourceMod;
@ -68,8 +68,7 @@ private:
*/ */
ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength); ConfigResult SetConfigOption(const char *option, const char *value, ConfigSource, char *Error, size_t maxlength);
private: private:
BaseStringTable m_Strings; StringHashMap<ke::AString> m_KeyValues;
StringHashMap<int> m_KeyValues;
}; };
extern bool SM_AreConfigsExecuted(); extern bool SM_AreConfigsExecuted();

View File

@ -45,6 +45,7 @@ class AString
: length_(0) : length_(0)
{ {
} }
explicit AString(const char *str) { explicit AString(const char *str) {
set(str, strlen(str)); set(str, strlen(str));
} }
@ -80,6 +81,12 @@ class AString
} }
return *this; return *this;
} }
AString &operator =(Moveable<AString> other) {
chars_ = other->chars_.take();
length_ = other->length_;
other->length_ = 0;
return *this;
}
int compare(const char *str) const { int compare(const char *str) const {
return strcmp(chars(), str); return strcmp(chars(), str);