From ea5a042046a25bf969852909c9ed5d598e39a03e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 18 Nov 2010 03:00:08 +0000 Subject: [PATCH] Cache the list of dictionary languages Originally committed to SVN as r4847. --- aegisub/src/spellchecker_hunspell.cpp | 14 ++++++-------- aegisub/src/spellchecker_hunspell.h | 5 ++++- aegisub/src/subs_edit_ctrl.cpp | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/aegisub/src/spellchecker_hunspell.cpp b/aegisub/src/spellchecker_hunspell.cpp index d507fd826..06b4a1ca9 100644 --- a/aegisub/src/spellchecker_hunspell.cpp +++ b/aegisub/src/spellchecker_hunspell.cpp @@ -155,6 +155,8 @@ wxArrayString HunspellSpellChecker::GetSuggestions(wxString word) { } wxArrayString HunspellSpellChecker::GetLanguageList() { + if (!languages.empty()) return languages; + wxArrayString dic, aff; // Get list of dictionaries @@ -178,7 +180,6 @@ wxArrayString HunspellSpellChecker::GetLanguageList() { for (size_t i = 0; i < aff.size(); ++i) aff[i].resize(aff[i].size() - 4); // Verify that each aff has a dic - wxArrayString ret; for (size_t i = 0, j = 0; i < dic.size() && j < aff.size(); ) { int cmp = dic[i].Cmp(aff[j]); if (cmp < 0) ++i; @@ -187,13 +188,13 @@ wxArrayString HunspellSpellChecker::GetLanguageList() { // Don't insert a language twice if it's in both the user dir and // the app's dir wxString name = wxFileName(aff[j]).GetName(); - if (ret.empty() || name != ret.back()) - ret.push_back(name); + if (languages.empty() || name != languages.back()) + languages.push_back(name); ++i; ++j; } } - return ret; + return languages; } void HunspellSpellChecker::SetLanguage(wxString language) { @@ -226,8 +227,6 @@ void HunspellSpellChecker::SetLanguage(wxString language) { conv.reset(new agi::charset::IconvWrapper("utf-8", hunspell->get_dic_encoding())); rconv.reset(new agi::charset::IconvWrapper(hunspell->get_dic_encoding(), "utf-8")); - if (userDicPath == dicPath || !wxFileExists(userDicPath)) return; - try { std::auto_ptr stream(agi::io::Open(STD_STR(userDicPath))); agi::line_iterator userDic(*stream.get()); @@ -249,8 +248,7 @@ void HunspellSpellChecker::SetLanguage(wxString language) { } } catch (agi::Exception const&) { - // File ceased to exist between when we checked and when we tried to - // open it or we don't have permission to read it for whatever reason + // File doesn't exist or we don't have permission to read it } } diff --git a/aegisub/src/spellchecker_hunspell.h b/aegisub/src/spellchecker_hunspell.h index cb06268cb..0b31f518c 100644 --- a/aegisub/src/spellchecker_hunspell.h +++ b/aegisub/src/spellchecker_hunspell.h @@ -52,10 +52,13 @@ class HunspellSpellChecker : public SpellChecker { /// Hunspell instance std::auto_ptr hunspell; - /// Conversion buffer + /// Conversions between the dictionary charset and utf-8 std::auto_ptr conv; std::auto_ptr rconv; + /// Languages which we have dictionaries for + wxArrayString languages; + /// Path to user-local dictionary. wxString userDicPath; diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index c05a2629d..e8a3c831b 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -827,7 +827,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) { } } - wxArrayString langs = spellchecker->GetLanguageList(); // This probably should be cached... + wxArrayString langs = spellchecker->GetLanguageList(); wxString curLang = lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString()); // Languages