diff --git a/src/rime/dict/user_dictionary.cc b/src/rime/dict/user_dictionary.cc index f2105c45b..0387b05a6 100644 --- a/src/rime/dict/user_dictionary.cc +++ b/src/rime/dict/user_dictionary.cc @@ -30,7 +30,7 @@ struct DfsState { TickCount present_tick; Code code; vector credibility; - map query_result; + hash_map query_result; an accessor; string key; string value; @@ -43,7 +43,8 @@ struct DfsState { bool IsPrefixMatch(const string& prefix) { return boost::starts_with(key, prefix); } - void RecruitEntry(size_t pos, map* syllabary = nullptr); + void RecruitEntry(size_t pos, + hash_map* syllabary = nullptr); bool NextEntry() { if (!accessor->GetNextRecord(&key, &value)) { key.clear(); @@ -68,7 +69,8 @@ struct DfsState { } }; -void DfsState::RecruitEntry(size_t pos, map* syllabary) { +void DfsState::RecruitEntry(size_t pos, + hash_map* syllabary) { string full_code; auto e = UserDictionary::CreateDictEntry(key, value, present_tick, credibility.back(), @@ -292,7 +294,8 @@ void UserDictionary::DfsLookup(const SyllableGraph& syll_graph, } } -static an collect(map* source) { +static an collect( + hash_map* source) { auto result = New(); for (auto& x : *source) { (*result)[x.first].SetEntries(std::move(x.second)); @@ -502,7 +505,10 @@ bool UserDictionary::TranslateCodeToString(const Code& code, string* result) { return false; result->clear(); for (const SyllableId& syllable_id : code) { - string spelling = table_->GetSyllableById(syllable_id); + string spelling = rev_syllabary_.count(syllable_id) + ? rev_syllabary_[syllable_id] + : (rev_syllabary_[syllable_id] = + table_->GetSyllableById(syllable_id)); if (spelling.empty()) { LOG(ERROR) << "Error translating syllable_id '" << syllable_id << "'."; result->clear(); diff --git a/src/rime/dict/user_dictionary.h b/src/rime/dict/user_dictionary.h index 3e289a842..ba9ec9f2c 100644 --- a/src/rime/dict/user_dictionary.h +++ b/src/rime/dict/user_dictionary.h @@ -99,7 +99,8 @@ class UserDictionary : public Class { an db_; an table_; an prism_; - map syllabary_; + hash_map syllabary_; + hash_map rev_syllabary_; TickCount tick_ = 0; time_t transaction_time_ = 0; }; @@ -111,7 +112,7 @@ class UserDictionaryComponent : public UserDictionary::Component { UserDictionary* Create(const string& dict_name, const string& db_class); private: - map> db_pool_; + hash_map> db_pool_; }; } // namespace rime