From a7e5e613f86963c8bf82248ab044e0ea36e42fbc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 16 Mar 2018 12:09:30 +0300 Subject: LIST<>::indexOf(T**) - fast index calculation for direct iterators --- plugins/PluginUpdater/src/DlgListNew.cpp | 28 ++++++++++++---------------- plugins/PluginUpdater/src/DlgUpdate.cpp | 26 +++++++++++++------------- 2 files changed, 25 insertions(+), 29 deletions(-) (limited to 'plugins/PluginUpdater') diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 81f40481b7..7151781255 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -224,24 +224,22 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /// bool enableOk = false; OBJLIST &todo = *(OBJLIST *)lParam; - for (int i = 0; i < todo.getCount(); i++) { - auto &p = todo[i]; - + for (auto &p : todo) { LVITEM lvi = { 0 }; lvi.mask = LVIF_PARAM | LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE; int groupId = 4; - if (wcschr(p.tszOldName, L'\\') != nullptr) - groupId = (wcsstr(p.tszOldName, L"Plugins") != nullptr) ? 1 : ((wcsstr(p.tszOldName, L"Languages") != nullptr) ? 3 : 2); + if (wcschr(p->tszOldName, L'\\') != nullptr) + groupId = (wcsstr(p->tszOldName, L"Plugins") != nullptr) ? 1 : ((wcsstr(p->tszOldName, L"Languages") != nullptr) ? 3 : 2); - lvi.iItem = i; - lvi.lParam = (LPARAM)&todo[i]; + lvi.iItem = todo.indexOf(&p); + lvi.lParam = (LPARAM)p; lvi.iGroupId = groupId; lvi.iImage = ((groupId == 1) ? 0 : -1); - lvi.pszText = p.tszOldName; + lvi.pszText = p->tszOldName; ListView_InsertItem(hwndList, &lvi); - if (p.bEnabled) { + if (p->bEnabled) { enableOk = true; ListView_SetCheckState(hwndList, lvi.iItem, 1); } @@ -273,8 +271,8 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem); bool enableOk = false; - for (int i = 0; i < todo.getCount(); ++i) { - if (p->bEnabled) { + for (auto &it : todo) { + if (it->bEnabled) { enableOk = true; break; } @@ -396,14 +394,12 @@ static void GetList(void *) FILELIST *UpdateFiles = new FILELIST(20); VARSW dirname(L"%miranda_path%"); - for (int i = 0; i < hashes.getCount(); i++) { - ServListEntry &hash = hashes[i]; - + for (auto &it : hashes) { wchar_t tszPath[MAX_PATH]; - mir_snwprintf(tszPath, L"%s\\%s", dirname, hash.m_name); + mir_snwprintf(tszPath, L"%s\\%s", dirname, it->m_name); if (GetFileAttributes(tszPath) == INVALID_FILE_ATTRIBUTES) { - FILEINFO *FileInfo = ServerEntryToFileInfo(hash, baseUrl, tszPath); + FILEINFO *FileInfo = ServerEntryToFileInfo(*it, baseUrl, tszPath); UpdateFiles->insert(FileInfo); } } diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 467e7e44ce..f5058c63a0 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -30,9 +30,9 @@ static void SelectAll(HWND hDlg, bool bEnable) OBJLIST &todo = *(OBJLIST *)GetWindowLongPtr(hDlg, GWLP_USERDATA); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); - for (int i=0; i < todo.getCount(); i++) { - ListView_SetCheckState(hwndList, i, bEnable); - db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(todo[i].tszOldName)), todo[i].bEnabled = bEnable); + for (auto &it : todo) { + ListView_SetCheckState(hwndList, todo.indexOf(&it), bEnable); + db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(it->tszOldName)), it->bEnabled = bEnable); } } @@ -266,23 +266,23 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM bool enableOk = false; OBJLIST &todo = *(OBJLIST *)lParam; - for (int i = 0; i < todo.getCount(); ++i) { + for (auto &it : todo) { LVITEM lvI = {0}; lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_GROUPID | LVIF_NORECOMPUTE; - lvI.iGroupId = (wcsstr(todo[i].tszOldName, L"Plugins") != nullptr) ? 1 : - ((wcsstr(todo[i].tszOldName, L"Languages") != nullptr) ? 3 : - ((wcsstr(todo[i].tszOldName, L"Icons") != nullptr) ? 4 : 2)); + lvI.iGroupId = (wcsstr(it->tszOldName, L"Plugins") != nullptr) ? 1 : + ((wcsstr(it->tszOldName, L"Languages") != nullptr) ? 3 : + ((wcsstr(it->tszOldName, L"Icons") != nullptr) ? 4 : 2)); lvI.iSubItem = 0; - lvI.lParam = (LPARAM)&todo[i]; - lvI.pszText = todo[i].tszOldName; - lvI.iItem = i; + lvI.lParam = (LPARAM)it; + lvI.pszText = it->tszOldName; + lvI.iItem = todo.indexOf(&it); ListView_InsertItem(hwndList, &lvI); - ListView_SetCheckState(hwndList, lvI.iItem, todo[i].bEnabled); - if (todo[i].bEnabled) + ListView_SetCheckState(hwndList, lvI.iItem, it->bEnabled); + if (it->bEnabled) enableOk = true; - SetStringText(hwndList,i,todo[i].bDeleteOnly ? TranslateT("Deprecated!") : TranslateT("Update found!")); + SetStringText(hwndList, lvI.iItem, it->bDeleteOnly ? TranslateT("Deprecated!") : TranslateT("Update found!")); } if(enableOk) EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); -- cgit v1.2.3