From 391980ce1e890445542441eeb5d9f9cc18ae1baf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 26 Jan 2018 22:31:20 +0300 Subject: code optimization --- plugins/Clist_modern/src/modern_clc.cpp | 42 +++++++++++----------- plugins/Clist_modern/src/modern_clcopts.cpp | 39 ++++++++++---------- plugins/Clist_modern/src/modern_clistopts.cpp | 8 ++--- plugins/Clist_modern/src/modern_clui.cpp | 9 ++--- plugins/Clist_modern/src/modern_contact.cpp | 7 ++-- .../Clist_modern/src/modern_rowheight_funcs.cpp | 16 ++++----- plugins/Clist_modern/src/modern_rowtemplateopt.cpp | 14 ++++---- .../Clist_modern/src/modern_statusbar_options.cpp | 8 ++--- plugins/Clist_modern/src/modern_sync.cpp | 3 +- 9 files changed, 72 insertions(+), 74 deletions(-) (limited to 'plugins/Clist_modern/src') diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 2feb1ebcfe..2b80d741cd 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -29,8 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "modern_clcpaint.h" -int ModernSkinOptInit(WPARAM wParam, LPARAM lParam); - /* * Private module variables */ @@ -69,23 +67,25 @@ static int clcHookIconsChanged(WPARAM, LPARAM) if (MirandaExiting()) return 0; - for (int i = 0; i < _countof(g_pAvatarOverlayIcons); i++) { - g_pAvatarOverlayIcons[i].listID = -1; - g_pStatusOverlayIcons[i].listID = -1; - } + for (auto &it : g_pAvatarOverlayIcons) + it.listID = -1; + for (auto &it : g_pStatusOverlayIcons) + it.listID = -1; if (hAvatarOverlays) ImageList_Destroy(hAvatarOverlays); hAvatarOverlays = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, _countof(g_pAvatarOverlayIcons) * 2, 1); - for (int i = 0; i < _countof(g_pAvatarOverlayIcons); i++) { - HICON hIcon = IcoLib_GetIcon(g_pAvatarOverlayIcons[i].name); - g_pAvatarOverlayIcons[i].listID = ImageList_AddIcon(hAvatarOverlays, hIcon); - IcoLib_Release(g_pAvatarOverlayIcons[i].name); + for (auto &it : g_pAvatarOverlayIcons) { + HICON hIcon = IcoLib_GetIcon(it.name); + it.listID = ImageList_AddIcon(hAvatarOverlays, hIcon); + IcoLib_Release(it.name); + } - hIcon = IcoLib_GetIcon(g_pStatusOverlayIcons[i].name); - g_pStatusOverlayIcons[i].listID = ImageList_AddIcon(hAvatarOverlays, hIcon); - IcoLib_Release(g_pStatusOverlayIcons[i].name); + for (auto &it : g_pStatusOverlayIcons) { + HICON hIcon = IcoLib_GetIcon(it.name); + it.listID = ImageList_AddIcon(hAvatarOverlays, hIcon); + IcoLib_Release(it.name); } g_hListeningToIcon = IcoLib_GetIcon("LISTENING_TO_ICON"); @@ -1564,18 +1564,18 @@ static int clcHookModulesLoaded(WPARAM, LPARAM) IcoLib_AddIcon(&sid); sid.section.a = LPGEN("Contact list") "/" LPGEN("Avatar overlay"); - for (int i = 0; i < _countof(g_pAvatarOverlayIcons); i++) { - sid.description.a = g_pAvatarOverlayIcons[i].description; - sid.pszName = g_pAvatarOverlayIcons[i].name; - sid.iDefaultIndex = -g_pAvatarOverlayIcons[i].id; + for (auto &it : g_pAvatarOverlayIcons) { + sid.description.a = it.description; + sid.pszName = it.name; + sid.iDefaultIndex = -it.id; IcoLib_AddIcon(&sid); } sid.section.a = LPGEN("Contact list") "/" LPGEN("Status overlay"); - for (int i = 0; i < _countof(g_pStatusOverlayIcons); i++) { - sid.description.a = g_pStatusOverlayIcons[i].description; - sid.pszName = g_pStatusOverlayIcons[i].name; - sid.iDefaultIndex = -g_pStatusOverlayIcons[i].id; + for (auto &it : g_pStatusOverlayIcons) { + sid.description.a = it.description; + sid.pszName = it.name; + sid.iDefaultIndex = -it.id; IcoLib_AddIcon(&sid); } diff --git a/plugins/Clist_modern/src/modern_clcopts.cpp b/plugins/Clist_modern/src/modern_clcopts.cpp index 8a9a54e6d1..3ec5ff83e4 100644 --- a/plugins/Clist_modern/src/modern_clcopts.cpp +++ b/plugins/Clist_modern/src/modern_clcopts.cpp @@ -378,8 +378,8 @@ static INT_PTR CALLBACK DlgProcClistListOpts(HWND hwndDlg, UINT msg, WPARAM wPar SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_HIDEOFFLINEOPTS), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_HIDEOFFLINEOPTS), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); { DWORD exStyle = db_get_dw(0, "CLC", "ExStyle", GetDefaultExStyle()); - for (int i = 0; i < _countof(checkBoxToStyleEx); i++) - CheckDlgButton(hwndDlg, checkBoxToStyleEx[i].id, (exStyle&checkBoxToStyleEx[i].flag) ^ (checkBoxToStyleEx[i].flag*checkBoxToStyleEx[i].neg) ? BST_CHECKED : BST_UNCHECKED); + for (auto &it : checkBoxToStyleEx) + CheckDlgButton(hwndDlg, it.id, (exStyle & it.flag) ^ (it.flag * it.neg) ? BST_CHECKED : BST_UNCHECKED); UDACCEL accel[2] = { { 0, 10 }, { 2, 50 } }; SendDlgItemMessage(hwndDlg, IDC_SMOOTHTIMESPIN, UDM_SETRANGE, 0, MAKELONG(999, 0)); @@ -439,9 +439,9 @@ static INT_PTR CALLBACK DlgProcClistListOpts(HWND hwndDlg, UINT msg, WPARAM wPar switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: DWORD exStyle = 0; - for (int i = 0; i < _countof(checkBoxToStyleEx); i++) - if ((IsDlgButtonChecked(hwndDlg, checkBoxToStyleEx[i].id) == 0) == checkBoxToStyleEx[i].neg) - exStyle |= checkBoxToStyleEx[i].flag; + for (auto &it : checkBoxToStyleEx) + if ((IsDlgButtonChecked(hwndDlg, it.id) == 0) == it.neg) + exStyle |= it.flag; db_set_dw(0, "CLC", "ExStyle", exStyle); DWORD fullGreyoutFlags = MakeCheckBoxTreeFlags(GetDlgItem(hwndDlg, IDC_GREYOUTOPTS)); @@ -500,14 +500,13 @@ static INT_PTR CALLBACK DlgProcClistOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CheckDlgButton(hwndDlg, IDC_HILIGHTMODE2, db_get_b(0, "CLC", "HiLightMode", SETTING_HILIGHTMODE_DEFAULT) == 2 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_HILIGHTMODE3, db_get_b(0, "CLC", "HiLightMode", SETTING_HILIGHTMODE_DEFAULT) == 3 ? BST_CHECKED : BST_UNCHECKED); { - int i, item; int s1, s2, s3; - for (i = 0; i < _countof(sortby); i++) { - item = SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_ADDSTRING, 0, (LPARAM)TranslateW(sortby[i])); + for (auto &it : sortby) { + int item = SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_SETITEMDATA, item, 0); - item = SendDlgItemMessage(hwndDlg, IDC_CLSORT2, CB_ADDSTRING, 0, (LPARAM)TranslateW(sortby[i])); + item = SendDlgItemMessage(hwndDlg, IDC_CLSORT2, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_CLSORT2, CB_SETITEMDATA, item, 0); - item = SendDlgItemMessage(hwndDlg, IDC_CLSORT3, CB_ADDSTRING, 0, (LPARAM)TranslateW(sortby[i])); + item = SendDlgItemMessage(hwndDlg, IDC_CLSORT3, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_CLSORT3, CB_SETITEMDATA, item, 0); } @@ -515,7 +514,7 @@ static INT_PTR CALLBACK DlgProcClistOpts(HWND hwndDlg, UINT msg, WPARAM wParam, s2 = db_get_b(0, "CList", "SortBy2", SETTING_SORTBY2_DEFAULT); s3 = db_get_b(0, "CList", "SortBy3", SETTING_SORTBY3_DEFAULT); - for (i = 0; i < _countof(sortby); i++) { + for (int i = 0; i < _countof(sortby); i++) { if (s1 == sortbyValue[i]) SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_SETCURSEL, i, 0); if (s2 == sortbyValue[i]) @@ -799,8 +798,8 @@ static INT_PTR CALLBACK DlgProcClistBehaviourOpts(HWND hwndDlg, UINT msg, WPARAM EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC01), IsDlgButtonChecked(hwndDlg, IDC_AUTOHIDE)); { wchar_t *hidemode[] = { TranslateT("Hide to tray"), TranslateT("Behind left edge"), TranslateT("Behind right edge") }; - for (int i = 0; i < _countof(hidemode); i++) { - int item = SendDlgItemMessage(hwndDlg, IDC_HIDEMETHOD, CB_ADDSTRING, 0, (LPARAM)hidemode[i]); + for (auto &it : hidemode) { + int item = SendDlgItemMessage(hwndDlg, IDC_HIDEMETHOD, CB_ADDSTRING, 0, (LPARAM)it); SendDlgItemMessage(hwndDlg, IDC_HIDEMETHOD, CB_SETITEMDATA, item, 0); SendDlgItemMessage(hwndDlg, IDC_HIDEMETHOD, CB_SETCURSEL, db_get_b(0, "ModernData", "HideBehind", SETTING_HIDEBEHIND_DEFAULT), 0); } @@ -1356,8 +1355,8 @@ static INT_PTR CALLBACK DlgProcClcBkgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, case M_BKGR_UPDATE: { int isChecked = IsDlgButtonChecked(hwndDlg, IDC_BITMAP); - for (int indx = 0; indx < _countof(bitmapRelatedControls); indx++) - EnableWindow(GetDlgItem(hwndDlg, bitmapRelatedControls[indx]), isChecked); + for (auto &it : bitmapRelatedControls) + EnableWindow(GetDlgItem(hwndDlg, it), isChecked); } break; @@ -1526,11 +1525,11 @@ int ClcOptInit(WPARAM wParam, LPARAM) odp.pfnDlgProc = DlgProcClistListOpts; odp.flags = ODPF_BOLDGROUPS; - for (int i = 0; i < _countof(clist_opt_items); i++) { - odp.pszTemplate = MAKEINTRESOURCEA(clist_opt_items[i].id); - odp.szTab.a = clist_opt_items[i].name; - odp.pfnDlgProc = clist_opt_items[i].wnd_proc; - odp.flags = ODPF_BOLDGROUPS | clist_opt_items[i].flag; + for (auto &it : clist_opt_items) { + odp.pszTemplate = MAKEINTRESOURCEA(it.id); + odp.szTab.a = it.name; + odp.pfnDlgProc = it.wnd_proc; + odp.flags = ODPF_BOLDGROUPS | it.flag; Options_AddPage(wParam, &odp); } diff --git a/plugins/Clist_modern/src/modern_clistopts.cpp b/plugins/Clist_modern/src/modern_clistopts.cpp index 210d57dedb..da51bc085a 100644 --- a/plugins/Clist_modern/src/modern_clistopts.cpp +++ b/plugins/Clist_modern/src/modern_clistopts.cpp @@ -937,10 +937,10 @@ int CListOptInit(WPARAM wParam, LPARAM) odp.szTitle.a = LPGEN("Row items"); odp.flags = ODPF_BOLDGROUPS; - for (int i = 0; i < _countof(row_opt_items); i++) { - odp.pszTemplate = MAKEINTRESOURCEA(row_opt_items[i].id); - odp.szTab.a = row_opt_items[i].name; - odp.pfnDlgProc = row_opt_items[i].wnd_proc; + for (auto &it : row_opt_items) { + odp.pszTemplate = MAKEINTRESOURCEA(it.id); + odp.szTab.a = it.name; + odp.pfnDlgProc = it.wnd_proc; Options_AddPage(wParam, &odp); } return 0; diff --git a/plugins/Clist_modern/src/modern_clui.cpp b/plugins/Clist_modern/src/modern_clui.cpp index 074ba54b7c..6f0eb8630a 100644 --- a/plugins/Clist_modern/src/modern_clui.cpp +++ b/plugins/Clist_modern/src/modern_clui.cpp @@ -470,10 +470,11 @@ HICON GetMainStatusOverlay(int STATUS) void UnloadAvatarOverlayIcon() { - for (int i = 0; i < _countof(g_pAvatarOverlayIcons); i++) { - g_pAvatarOverlayIcons[i].listID = -1; - g_pStatusOverlayIcons[i].listID = -1; - } + for (auto &it : g_pAvatarOverlayIcons) + it.listID = -1; + for (auto &it : g_pStatusOverlayIcons) + it.listID = -1; + ImageList_Destroy(hAvatarOverlays); hAvatarOverlays = nullptr; DestroyIcon_protect(g_hListeningToIcon); diff --git a/plugins/Clist_modern/src/modern_contact.cpp b/plugins/Clist_modern/src/modern_contact.cpp index 45f4c29615..3e15378cf1 100644 --- a/plugins/Clist_modern/src/modern_contact.cpp +++ b/plugins/Clist_modern/src/modern_contact.cpp @@ -51,9 +51,10 @@ static int GetContactStatus(MCONTACT hContact) static int GetStatusModeOrdering(int statusMode) { - for (int i = 0; i < _countof(statusModeOrder); i++) - if (statusModeOrder[i].status == statusMode) - return statusModeOrder[i].order; + for (auto &it : statusModeOrder) + if (it.status == statusMode) + return it.order; + return 1000; } diff --git a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp index 8c09d9f65c..3bf61c98a3 100644 --- a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp +++ b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp @@ -343,15 +343,15 @@ static int other_fonts[] = { FONTID_OPENGROUPS, FONTID_OPENGROUPCOUNTS, FONTID_C int RowHeights_GetMaxRowHeight(ClcData *dat, HWND hwnd) { - int max_height = 0, i, tmp; + int max_height = 0; DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); if (!dat->text_ignore_size_for_row_height) { // Get contact font size - tmp = 0; - for (i = 0; i < _countof(contact_fonts); i++) - if (tmp < dat->fontModernInfo[contact_fonts[i]].fontHeight) - tmp = dat->fontModernInfo[contact_fonts[i]].fontHeight; + int tmp = 0; + for (auto &it : contact_fonts) + if (tmp < dat->fontModernInfo[it].fontHeight) + tmp = dat->fontModernInfo[it].fontHeight; if (dat->text_replace_smileys && dat->first_line_draw_smileys && !dat->text_resize_smileys) tmp = max(tmp, dat->text_smiley_height); @@ -373,9 +373,9 @@ int RowHeights_GetMaxRowHeight(ClcData *dat, HWND hwnd) } // Get other font sizes - for (i = 0; i < _countof(other_fonts); i++) - if (max_height < dat->fontModernInfo[other_fonts[i]].fontHeight) - max_height = dat->fontModernInfo[other_fonts[i]].fontHeight; + for (auto &it : other_fonts) + if (max_height < dat->fontModernInfo[it].fontHeight) + max_height = dat->fontModernInfo[it].fontHeight; } // Avatar size diff --git a/plugins/Clist_modern/src/modern_rowtemplateopt.cpp b/plugins/Clist_modern/src/modern_rowtemplateopt.cpp index 5d3cbcfb1f..1ac420b9bf 100644 --- a/plugins/Clist_modern/src/modern_rowtemplateopt.cpp +++ b/plugins/Clist_modern/src/modern_rowtemplateopt.cpp @@ -354,24 +354,22 @@ INT_PTR CALLBACK DlgTmplEditorOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM SendDlgItemMessage(hwndDlg, IDC_SPINCONTWIDTH, UDM_SETRANGE, 0, MAKELONG(999, 0)); SendDlgItemMessage(hwndDlg, IDC_SPINCONTHEIGHT, UDM_SETRANGE, 0, MAKELONG(999, 0)); - int i, item; - - for (i = 0; i < _countof(types); i++) { - item = SendDlgItemMessage(hwndDlg, IDC_CONTTYPE, CB_ADDSTRING, 0, (LPARAM)TranslateW(types[i])); + for (auto &it : types) { + int item = SendDlgItemMessage(hwndDlg, IDC_CONTTYPE, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_CONTTYPE, CB_SETITEMDATA, item, 0); } SendDlgItemMessage(hwndDlg, IDC_CONTTYPE, CB_SETCURSEL, 0, 0); wchar_t *h_alignment[] = { L"left", L"hCenter", L"right" }; - for (i = 0; i < _countof(h_alignment); i++) { - item = SendDlgItemMessage(hwndDlg, IDC_HALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(h_alignment[i])); + for (auto &it : h_alignment) { + int item = SendDlgItemMessage(hwndDlg, IDC_HALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_HALIGN, CB_SETITEMDATA, item, 0); } SendDlgItemMessage(hwndDlg, IDC_HALIGN, CB_SETCURSEL, 0, 0); wchar_t *v_alignment[] = { L"top", L"vCenter", L"bottom" }; - for (i = 0; i < _countof(v_alignment); i++) { - item = SendDlgItemMessage(hwndDlg, IDC_VALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(v_alignment[i])); + for (auto &it : v_alignment) { + int item = SendDlgItemMessage(hwndDlg, IDC_VALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_VALIGN, CB_SETITEMDATA, item, 0); } SendDlgItemMessage(hwndDlg, IDC_VALIGN, CB_SETCURSEL, 0, 0); diff --git a/plugins/Clist_modern/src/modern_statusbar_options.cpp b/plugins/Clist_modern/src/modern_statusbar_options.cpp index 99fd49ffe1..b2baf89122 100644 --- a/plugins/Clist_modern/src/modern_statusbar_options.cpp +++ b/plugins/Clist_modern/src/modern_statusbar_options.cpp @@ -238,15 +238,15 @@ INT_PTR CALLBACK DlgProcSBarOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l { wchar_t *align[] = { LPGENW("Left"), LPGENW("Center"), LPGENW("Right") }; - for (int i = 0; i < _countof(align); i++) - SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(align[i])); + for (auto &it : align) + SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_SBAR_HORIZ_ALIGN, CB_SETCURSEL, db_get_b(0, "CLUI", "Align", SETTING_ALIGN_DEFAULT), 0); } { wchar_t *align[] = { LPGENW("Top"), LPGENW("Center"), LPGENW("Bottom") }; - for (int i = 0; i < _countof(align); i++) - SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(align[i])); + for (auto &it : align) + SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_SBAR_VERT_ALIGN, CB_SETCURSEL, db_get_b(0, "CLUI", "VAlign", SETTING_VALIGN_DEFAULT), 0); } diff --git a/plugins/Clist_modern/src/modern_sync.cpp b/plugins/Clist_modern/src/modern_sync.cpp index 2715e8da36..50bec6b3dc 100644 --- a/plugins/Clist_modern/src/modern_sync.cpp +++ b/plugins/Clist_modern/src/modern_sync.cpp @@ -81,10 +81,9 @@ int SyncCall(void * vproc, int count, ...) { LPARAM params[5]; va_list va; - int i; params[0] = (LPARAM)count; va_start(va, count); - for (i = 0; i < count && i < _countof(params) - 1; i++) + for (int i = 0; i < count && i < _countof(params) - 1; i++) params[i + 1] = va_arg(va, LPARAM); va_end(va); -- cgit v1.2.3