Switch Translator to hash tables (bug 5878 part 2, r=ds).
This commit is contained in:
parent
3b9037397a
commit
04bb2d1066
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* vim: set ts=4 :
|
||||
* vim: set ts=4 sw=4 tw=99 noet:
|
||||
* =============================================================================
|
||||
* SourceMod
|
||||
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
||||
@ -210,12 +210,7 @@ SMCResult CPhraseFile::ReadSMC_NewSection(const SMCStates *states, const char *n
|
||||
m_ParseState = PPS_InPhrase;
|
||||
recognized = true;
|
||||
|
||||
int *pvalue;
|
||||
if ((pvalue = m_PhraseLookup.retrieve(name)) != NULL)
|
||||
{
|
||||
m_CurPhrase = *pvalue;
|
||||
}
|
||||
else
|
||||
if (!m_PhraseLookup.retrieve(name, &m_CurPhrase))
|
||||
{
|
||||
phrase_t *pPhrase;
|
||||
|
||||
@ -659,11 +654,11 @@ TransError CPhraseFile::GetTranslation(const char *szPhrase, unsigned int lang_i
|
||||
return Trans_BadLanguage;
|
||||
}
|
||||
|
||||
int *pvalue;
|
||||
if ((pvalue = m_PhraseLookup.retrieve(szPhrase)) == NULL)
|
||||
int address;
|
||||
if (!m_PhraseLookup.retrieve(szPhrase, &address))
|
||||
return Trans_BadPhrase;
|
||||
|
||||
phrase_t *pPhrase = (phrase_t *)m_pMemory->GetAddress(*pvalue);
|
||||
phrase_t *pPhrase = (phrase_t *)m_pMemory->GetAddress(address);
|
||||
trans_t *trans = (trans_t *)m_pMemory->GetAddress(pPhrase->trans_tbl);
|
||||
|
||||
trans = &trans[lang_id];
|
||||
@ -769,15 +764,7 @@ void Translator::OnSourceModShutdown()
|
||||
|
||||
bool Translator::GetLanguageByCode(const char *code, unsigned int *index)
|
||||
{
|
||||
unsigned int *pindex;
|
||||
|
||||
if ((pindex = m_LCodeLookup.retrieve(code)) == NULL)
|
||||
return false;
|
||||
|
||||
if (index)
|
||||
*index = *pindex;
|
||||
|
||||
return true;
|
||||
return m_LCodeLookup.retrieve(code, index);
|
||||
}
|
||||
|
||||
bool Translator::GetLanguageByName(const char *name, unsigned int *index)
|
||||
@ -794,15 +781,7 @@ bool Translator::GetLanguageByName(const char *name, unsigned int *index)
|
||||
}
|
||||
lower[len] = '\0';
|
||||
|
||||
unsigned int *pIndex;
|
||||
|
||||
if ((pIndex = m_LAliases.retrieve(lower)) == NULL)
|
||||
return false;
|
||||
|
||||
if (index)
|
||||
*index = *pIndex;
|
||||
|
||||
return true;
|
||||
return m_LAliases.retrieve(lower, index);
|
||||
}
|
||||
|
||||
unsigned int Translator::GetLanguageCount()
|
||||
@ -863,19 +842,13 @@ void Translator::RebuildLanguageDatabase(const char *lang_header_file)
|
||||
smcore.LogError("[SM] Parse error (line %d, column %d): %s", states.line, states.col, str_err);
|
||||
}
|
||||
|
||||
unsigned int *pServerLang;
|
||||
|
||||
if ((pServerLang = m_LCodeLookup.retrieve(m_InitialLang)) == NULL)
|
||||
if (!m_LCodeLookup.retrieve(m_InitialLang, &m_ServerLang))
|
||||
{
|
||||
smcore.LogError("Server language was set to bad language \"%s\" -- reverting to English", m_InitialLang);
|
||||
|
||||
smcore.strncopy(m_InitialLang, "en", sizeof(m_InitialLang));
|
||||
m_ServerLang = SOURCEMOD_LANGUAGE_ENGLISH;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ServerLang = *pServerLang;
|
||||
}
|
||||
|
||||
if (!m_Languages.size())
|
||||
{
|
||||
@ -948,15 +921,11 @@ bool Translator::AddLanguage(const char *langcode, const char *description)
|
||||
}
|
||||
lower[len] = '\0';
|
||||
|
||||
if (m_LAliases.retrieve(lower))
|
||||
if (m_LAliases.contains(lower))
|
||||
return false;
|
||||
|
||||
unsigned int idx;
|
||||
if (unsigned int *pIdx = m_LCodeLookup.retrieve(langcode))
|
||||
{
|
||||
idx = *pIdx;
|
||||
}
|
||||
else
|
||||
if (!m_LCodeLookup.retrieve(langcode, &idx))
|
||||
{
|
||||
Language *pLanguage = new Language;
|
||||
idx = m_Languages.size();
|
||||
|
@ -33,7 +33,7 @@
|
||||
#define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
|
||||
|
||||
#include "common_logic.h"
|
||||
#include <sm_trie_tpl.h>
|
||||
#include <sm_stringhashmap.h>
|
||||
#include <sh_string.h>
|
||||
#include <sh_vector.h>
|
||||
#include "sm_memtable.h"
|
||||
@ -79,7 +79,7 @@ private:
|
||||
void ParseError(const char *message, ...);
|
||||
void ParseWarning(const char *message, ...);
|
||||
private:
|
||||
KTrie<int> m_PhraseLookup;
|
||||
StringHashMap<int> m_PhraseLookup;
|
||||
String m_File;
|
||||
Translator *m_pTranslator;
|
||||
PhraseParseState m_ParseState;
|
||||
@ -152,8 +152,8 @@ private:
|
||||
CVector<Language *> m_Languages;
|
||||
CVector<CPhraseFile *> m_Files;
|
||||
BaseStringTable *m_pStringTab;
|
||||
KTrie<unsigned int> m_LCodeLookup;
|
||||
KTrie<unsigned int> m_LAliases;
|
||||
StringHashMap<unsigned int> m_LCodeLookup;
|
||||
StringHashMap<unsigned int> m_LAliases;
|
||||
bool m_InLanguageSection;
|
||||
String m_CustomError;
|
||||
unsigned int m_ServerLang;
|
||||
|
Loading…
Reference in New Issue
Block a user