1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 07:53:53 +00:00

optimized keyword parsing

This commit is contained in:
myrix 2021-12-18 20:07:41 +03:00
parent 97d285d1c1
commit 0688f55171

View file

@ -47,19 +47,25 @@ namespace MWDialogue
void tokenizeKeywords(const std::string & text, std::vector<Token> & tokens)
{
const MWWorld::Store<ESM::Dialogue> & dialogs =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
static bool keywordSearchInitialized = false;
static KeywordSearch<std::string, int /*unused*/> keywordSearch;
std::vector<std::string> keywordList;
keywordList.reserve(dialogs.getSize());
for (const auto& it : dialogs)
keywordList.push_back(Misc::StringUtils::lowerCase(it.mId));
sort(keywordList.begin(), keywordList.end());
if (!keywordSearchInitialized)
{
const MWWorld::Store<ESM::Dialogue> & dialogs =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
KeywordSearch<std::string, int /*unused*/> keywordSearch;
std::vector<std::string> keywordList;
keywordList.reserve(dialogs.getSize());
for (const auto& it : dialogs)
keywordList.push_back(Misc::StringUtils::lowerCase(it.mId));
sort(keywordList.begin(), keywordList.end());
for (const auto& it : keywordList)
keywordSearch.seed(it, 0 /*unused*/);
for (const auto& it : keywordList)
keywordSearch.seed(it, 0 /*unused*/);
keywordSearchInitialized = true;
}
std::vector<KeywordSearch<std::string, int /*unused*/>::Match> matches;
keywordSearch.highlightKeywords(text.begin(), text.end(), matches);