mirror of
https://github.com/OpenMW/openmw.git
synced 2025-11-08 20:16:43 +00:00
optimized keyword parsing
This commit is contained in:
parent
97d285d1c1
commit
0688f55171
1 changed files with 16 additions and 10 deletions
|
|
@ -46,6 +46,11 @@ namespace MWDialogue
|
||||||
}
|
}
|
||||||
|
|
||||||
void tokenizeKeywords(const std::string & text, std::vector<Token> & tokens)
|
void tokenizeKeywords(const std::string & text, std::vector<Token> & tokens)
|
||||||
|
{
|
||||||
|
static bool keywordSearchInitialized = false;
|
||||||
|
static KeywordSearch<std::string, int /*unused*/> keywordSearch;
|
||||||
|
|
||||||
|
if (!keywordSearchInitialized)
|
||||||
{
|
{
|
||||||
const MWWorld::Store<ESM::Dialogue> & dialogs =
|
const MWWorld::Store<ESM::Dialogue> & dialogs =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
|
||||||
|
|
@ -56,11 +61,12 @@ namespace MWDialogue
|
||||||
keywordList.push_back(Misc::StringUtils::lowerCase(it.mId));
|
keywordList.push_back(Misc::StringUtils::lowerCase(it.mId));
|
||||||
sort(keywordList.begin(), keywordList.end());
|
sort(keywordList.begin(), keywordList.end());
|
||||||
|
|
||||||
KeywordSearch<std::string, int /*unused*/> keywordSearch;
|
|
||||||
|
|
||||||
for (const auto& it : keywordList)
|
for (const auto& it : keywordList)
|
||||||
keywordSearch.seed(it, 0 /*unused*/);
|
keywordSearch.seed(it, 0 /*unused*/);
|
||||||
|
|
||||||
|
keywordSearchInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<KeywordSearch<std::string, int /*unused*/>::Match> matches;
|
std::vector<KeywordSearch<std::string, int /*unused*/>::Match> matches;
|
||||||
keywordSearch.highlightKeywords(text.begin(), text.end(), matches);
|
keywordSearch.highlightKeywords(text.begin(), text.end(), matches);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue