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/UserInfoEx/src/ctrl_annivedit.cpp | 4 +-- plugins/UserInfoEx/src/dlg_propsheet.cpp | 8 +++--- plugins/UserInfoEx/src/mir_icolib.cpp | 12 ++++---- plugins/UserInfoEx/src/psp_options.cpp | 48 +++++++++++++++---------------- plugins/UserInfoEx/src/svc_reminder.cpp | 8 +++--- 5 files changed, 39 insertions(+), 41 deletions(-) (limited to 'plugins/UserInfoEx/src') diff --git a/plugins/UserInfoEx/src/ctrl_annivedit.cpp b/plugins/UserInfoEx/src/ctrl_annivedit.cpp index 283710341a..7f43748282 100644 --- a/plugins/UserInfoEx/src/ctrl_annivedit.cpp +++ b/plugins/UserInfoEx/src/ctrl_annivedit.cpp @@ -366,8 +366,8 @@ INT_PTR CAnnivEditCtrl::DBWriteAnniversaries(MCONTACT hContact) do { ofs = mir_snprintf(szSet0, "Anniv%d", wIndex); ret = 1; - for (i = 0; i < _countof(szPrefix); i++) { - mir_strncpy(szSet0 + ofs, szPrefix[i], _countof(szSet0) - ofs); + for (auto &it : szPrefix) { + mir_strncpy(szSet0 + ofs, it, _countof(szSet0) - ofs); ret &= db_unset(hContact, USERINFO, szSet0); } } diff --git a/plugins/UserInfoEx/src/dlg_propsheet.cpp b/plugins/UserInfoEx/src/dlg_propsheet.cpp index 948b70dba8..3ab88e18a0 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.cpp +++ b/plugins/UserInfoEx/src/dlg_propsheet.cpp @@ -793,15 +793,15 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar static const WORD idMove[] = { IDC_PAGETITLE, IDC_PAGETITLEBG, IDC_PAGETITLEBG2, IDOK, IDCANCEL, IDAPPLY }; HWND hCtrl; - for (int i = 0; i < _countof(idResize); i++) { - if (hCtrl = GetDlgItem(hDlg, idResize[i])) { + for (auto &it : idResize) { + if (hCtrl = GetDlgItem(hDlg, it)) { GetWindowRect(hCtrl, &rc); OffsetRect(&rc, -pt.x, -pt.y); MoveWindow(hCtrl, rc.left, rc.top, rc.right - rc.left + addWidth, rc.bottom - rc.top, FALSE); } } - for (int k = 0; k < _countof(idMove); k++) { - if (hCtrl = GetDlgItem(hDlg, idMove[k])) { + for (auto &it : idMove) { + if (hCtrl = GetDlgItem(hDlg, it)) { GetWindowRect(hCtrl, &rc); OffsetRect(&rc, -pt.x, -pt.y); MoveWindow(hCtrl, rc.left + addWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); diff --git a/plugins/UserInfoEx/src/mir_icolib.cpp b/plugins/UserInfoEx/src/mir_icolib.cpp index cdb2783326..a197d9d27c 100644 --- a/plugins/UserInfoEx/src/mir_icolib.cpp +++ b/plugins/UserInfoEx/src/mir_icolib.cpp @@ -134,10 +134,10 @@ LPTSTR IcoLib_GetDefaultIconFileName() }; wchar_t absolute[MAX_PATH]; - for (int i = 0; i < _countof(path); i++) { - PathToAbsoluteW(path[i], absolute); + for (auto &it : path) { + PathToAbsoluteW(it, absolute); if (PathFileExists(absolute)) - return path[i]; + return it; } return nullptr; } @@ -330,8 +330,6 @@ void IcoLib_LoadModule() // load default icon if required ghDefIcon = (HICON)IcoLib_GetIcon(ICO_COMMON_DEFAULT, false); - for (int i = 0; i < _countof(icoDesc); i++) - IcoLib_RegisterIconHandleEx( - icoDesc[i].pszName, icoDesc[i].pszDesc, icoDesc[i].pszSection, - szDefaultFile, icoDesc[i].idResource, icoDesc[i].size, ghDefIcon); + for (auto &it : icoDesc) + IcoLib_RegisterIconHandleEx(it.pszName, it.pszDesc, it.pszSection, szDefaultFile, it.idResource, it.size, ghDefIcon); } diff --git a/plugins/UserInfoEx/src/psp_options.cpp b/plugins/UserInfoEx/src/psp_options.cpp index 0bab0f9a8d..f878983d09 100644 --- a/plugins/UserInfoEx/src/psp_options.cpp +++ b/plugins/UserInfoEx/src/psp_options.cpp @@ -276,22 +276,22 @@ static INT_PTR CALLBACK DlgProc_CommonOpts(HWND hDlg, UINT uMsg, WPARAM wParam, switch (((LPNMHDR)lParam)->code) { case PSN_INFOCHANGED: bInitialized = 0; - { - // menu item settings - for (int i = 0; i < _countof(ctrl_Menu); i++) { - int flag = db_get_b(NULL, MODNAME, ctrl_Menu[i].pszKey, 2); - // check button and enable / disable control - int idEnable[] = { ctrl_Menu[i].idCheckbox + 1, ctrl_Menu[i].idNONE, ctrl_Menu[i].idALL, ctrl_Menu[i].idEXIMPORT }; - EnableControls(hDlg, idEnable, _countof(idEnable), DBGetCheckBtn(hDlg, ctrl_Menu[i].idCheckbox, ctrl_Menu[i].pszKey, 0)); - // set radio button state - int id = ctrl_Menu[i].idNONE; //default - if ((flag & 4) == 4) - id = ctrl_Menu[i].idALL; - else if ((flag & 8) == 8) - id = ctrl_Menu[i].idEXIMPORT; - CheckRadioButton(hDlg, ctrl_Menu[i].idNONE, ctrl_Menu[i].idEXIMPORT, id); - } + + // menu item settings + for (auto &it : ctrl_Menu) { + int flag = db_get_b(NULL, MODNAME, it.pszKey, 2); + // check button and enable / disable control + int idEnable[] = { it.idCheckbox + 1, it.idNONE, it.idALL, it.idEXIMPORT }; + EnableControls(hDlg, idEnable, _countof(idEnable), DBGetCheckBtn(hDlg, it.idCheckbox, it.pszKey, 0)); + // set radio button state + int id = it.idNONE; //default + if ((flag & 4) == 4) + id = it.idALL; + else if ((flag & 8) == 8) + id = it.idEXIMPORT; + CheckRadioButton(hDlg, it.idNONE, it.idEXIMPORT, id); } + // extra icon settings CheckDlgButton(hDlg, CHECK_OPT_GENDER, g_eiGender ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, CHECK_OPT_EMAILICON, g_eiEmail ? BST_CHECKED : BST_UNCHECKED); @@ -308,12 +308,12 @@ static INT_PTR CALLBACK DlgProc_CommonOpts(HWND hDlg, UINT uMsg, WPARAM wParam, case PSN_APPLY: // menu item settings - for (int i = 0; i < _countof(ctrl_Menu); i++) { - int flag = IsDlgButtonChecked(hDlg, ctrl_Menu[i].idCheckbox); - flag |= IsDlgButtonChecked(hDlg, ctrl_Menu[i].idNONE) ? 2 : 0; - flag |= IsDlgButtonChecked(hDlg, ctrl_Menu[i].idALL) ? 4 : 0; - flag |= IsDlgButtonChecked(hDlg, ctrl_Menu[i].idEXIMPORT) ? 8 : 0; - db_set_b(NULL, MODNAME, ctrl_Menu[i].pszKey, (BYTE)flag); + for (auto &it : ctrl_Menu) { + int flag = IsDlgButtonChecked(hDlg, it.idCheckbox); + flag |= IsDlgButtonChecked(hDlg, it.idNONE) ? 2 : 0; + flag |= IsDlgButtonChecked(hDlg, it.idALL) ? 4 : 0; + flag |= IsDlgButtonChecked(hDlg, it.idEXIMPORT) ? 8 : 0; + db_set_b(NULL, MODNAME, it.pszKey, (BYTE)flag); } RebuildMenu(); @@ -359,9 +359,9 @@ static INT_PTR CALLBACK DlgProc_CommonOpts(HWND hDlg, UINT uMsg, WPARAM wParam, case CHECK_OPT_MI_GROUP: case CHECK_OPT_MI_SUBGROUP: case CHECK_OPT_MI_ACCOUNT: - for (int i = 0; i < _countof(ctrl_Menu); i++) { - if (ctrl_Menu[i].idCheckbox == LOWORD(wParam)) { - const int idMenuItems[] = { ctrl_Menu[i].idCheckbox + 1, ctrl_Menu[i].idNONE, ctrl_Menu[i].idALL, ctrl_Menu[i].idEXIMPORT }; + for (auto &it : ctrl_Menu) { + if (it.idCheckbox == LOWORD(wParam)) { + const int idMenuItems[] = { it.idCheckbox + 1, it.idNONE, it.idALL, it.idEXIMPORT }; EnableControls(hDlg, idMenuItems, _countof(idMenuItems), Button_GetCheck((HWND)lParam)); break; } diff --git a/plugins/UserInfoEx/src/svc_reminder.cpp b/plugins/UserInfoEx/src/svc_reminder.cpp index a48187a13f..0b50dfd8ed 100644 --- a/plugins/UserInfoEx/src/svc_reminder.cpp +++ b/plugins/UserInfoEx/src/svc_reminder.cpp @@ -598,11 +598,11 @@ void SvcReminderCheckAll(const ENotify notify) static int OnCListRebuildIcons(WPARAM, LPARAM) { - for (int i = 0; i < _countof(ghCListAnnivIcons); i++) - ghCListAnnivIcons[i] = INVALID_HANDLE_VALUE; + for (auto &it : ghCListAnnivIcons) + it = INVALID_HANDLE_VALUE; - for (int k = 0; k < _countof(ghCListBirthdayIcons); k++) - ghCListBirthdayIcons[k] = INVALID_HANDLE_VALUE; + for (auto &it : ghCListBirthdayIcons) + it = INVALID_HANDLE_VALUE; return 0; } -- cgit v1.2.3