summaryrefslogtreecommitdiff
path: root/plugins/SpellChecker
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-16 12:09:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-16 12:09:38 +0300
commita7e5e613f86963c8bf82248ab044e0ea36e42fbc (patch)
tree39e0e6b3ab4bcb55255302d3d1e989b31247bf7b /plugins/SpellChecker
parentecbca42677af470d672e66d3f6950af208f8f212 (diff)
LIST<>::indexOf(T**) - fast index calculation for direct iterators
Diffstat (limited to 'plugins/SpellChecker')
-rw-r--r--plugins/SpellChecker/src/dictionary.cpp6
-rw-r--r--plugins/SpellChecker/src/spellchecker.cpp5
-rw-r--r--plugins/SpellChecker/src/utils.cpp27
3 files changed, 19 insertions, 19 deletions
diff --git a/plugins/SpellChecker/src/dictionary.cpp b/plugins/SpellChecker/src/dictionary.cpp
index 98178f0a23..0bb88d0482 100644
--- a/plugins/SpellChecker/src/dictionary.cpp
+++ b/plugins/SpellChecker/src/dictionary.cpp
@@ -836,9 +836,11 @@ void GetHunspellDictionariesFromFolder(LIST<Dictionary> &dicts, wchar_t *path, w
// Check if dict is new
bool exists = false;
- for (int i = 0; i < dicts.getCount() && !exists; i++)
- if (mir_wstrcmp(dicts[i]->language, lang) == 0)
+ for (auto &it : dicts)
+ if (mir_wstrcmp(it->language, lang) == 0) {
exists = true;
+ break;
+ }
if (!exists) {
found = TRUE;
diff --git a/plugins/SpellChecker/src/spellchecker.cpp b/plugins/SpellChecker/src/spellchecker.cpp
index 4b495303c1..9770861c9c 100644
--- a/plugins/SpellChecker/src/spellchecker.cpp
+++ b/plugins/SpellChecker/src/spellchecker.cpp
@@ -144,12 +144,11 @@ static int ModulesLoaded(WPARAM, LPARAM)
sid.section.w = LPGENW("Spell Checker") L"/" LPGENW("Flags");
// Get language flags
- for (int i = 0; i < languages.getCount(); i++) {
- auto *p = languages[i];
+ for (auto &p : languages) {
sid.description.w = p->full_name;
char lang[32];
- mir_snprintf(lang, "spell_lang_%d", i);
+ mir_snprintf(lang, "spell_lang_%d", languages.indexOf(&p));
sid.pszName = lang;
HICON hFlag = nullptr, hFlagIcoLib = nullptr;
diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp
index 7dfcd12884..4fd399f44f 100644
--- a/plugins/SpellChecker/src/utils.cpp
+++ b/plugins/SpellChecker/src/utils.cpp
@@ -668,39 +668,38 @@ LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int GetClosestLanguage(wchar_t *lang_name)
{
- int i;
-
// Search the language by name
- for (i = 0; i < languages.getCount(); i++)
- if (mir_wstrcmpi(languages[i]->language, lang_name) == 0)
- return i;
+ for (auto &it : languages)
+ if (mir_wstrcmpi(it->language, lang_name) == 0)
+ return languages.indexOf(&it);
// Try searching by the prefix only
wchar_t lang[128];
mir_wstrncpy(lang, lang_name, _countof(lang));
{
wchar_t *p = wcschr(lang, '_');
- if (p != nullptr) *p = '\0';
+ if (p != nullptr)
+ *p = '\0';
}
// First check if there is a language that is only the prefix
- for (i = 0; i < languages.getCount(); i++)
- if (mir_wstrcmpi(languages[i]->language, lang) == 0)
- return i;
+ for (auto &it : languages)
+ if (mir_wstrcmpi(it->language, lang) == 0)
+ return languages.indexOf(&it);
// Now try any suffix
size_t len = mir_wstrlen(lang);
- for (i = 0; i < languages.getCount(); i++) {
- wchar_t *p = wcschr(languages[i]->language, '_');
+ for (auto &it : languages) {
+ wchar_t *p = wcschr(it->language, '_');
if (p == nullptr)
continue;
- size_t prefix_len = p - languages[i]->language;
+ size_t prefix_len = p - it->language;
if (prefix_len != len)
continue;
- if (wcsnicmp(languages[i]->language, lang_name, len) == 0)
- return i;
+ if (wcsnicmp(it->language, lang_name, len) == 0)
+ return languages.indexOf(&it);
}
return -1;