From 391980ce1e890445542441eeb5d9f9cc18ae1baf Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 26 Jan 2018 22:31:20 +0300 Subject: code optimization --- src/core/stdaway/src/sendmsg.cpp | 24 ++++++++++++------------ src/core/stdclist/src/clcopts.cpp | 14 +++++--------- src/core/stdclist/src/contact.cpp | 8 ++++---- src/core/stdidle/src/options.cpp | 4 ++-- src/core/stdmsg/src/msglog.cpp | 4 ++-- src/core/stdmsg/src/msgoptions.cpp | 8 ++++---- 6 files changed, 29 insertions(+), 33 deletions(-) (limited to 'src/core') diff --git a/src/core/stdaway/src/sendmsg.cpp b/src/core/stdaway/src/sendmsg.cpp index f7357e4f08..14ec7baffb 100644 --- a/src/core/stdaway/src/sendmsg.cpp +++ b/src/core/stdaway/src/sendmsg.cpp @@ -374,28 +374,28 @@ static INT_PTR CALLBACK DlgProcAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam dat = (AwayMsgDlgData*)mir_alloc(sizeof(AwayMsgDlgData)); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->oldPage = -1; - for (int i = 0; i < _countof(statusModes); i++) { - if (!(protoModeMsgFlags & Proto_Status2Flag(statusModes[i]))) + for (auto &it : statusModes) { + if (!(protoModeMsgFlags & Proto_Status2Flag(it))) continue; int j; if (hLst) { - j = SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModes[i], 0)); - SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_SETITEMDATA, j, statusModes[i]); + j = SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(it, 0)); + SendDlgItemMessage(hwndDlg, IDC_LST_STATUS, LB_SETITEMDATA, j, it); } else { - j = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModes[i], 0)); - SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, j, statusModes[i]); + j = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(it, 0)); + SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, j, it); } - dat->info[j].ignore = GetStatusModeByte(statusModes[i], "Ignore"); - dat->info[j].noDialog = GetStatusModeByte(statusModes[i], "NoDlg", true); - dat->info[j].usePrevious = GetStatusModeByte(statusModes[i], "UsePrev"); + dat->info[j].ignore = GetStatusModeByte(it, "Ignore"); + dat->info[j].noDialog = GetStatusModeByte(it, "NoDlg", true); + dat->info[j].usePrevious = GetStatusModeByte(it, "UsePrev"); DBVARIANT dbv; - if (db_get_ws(NULL, "SRAway", StatusModeToDbSetting(statusModes[i], "Default"), &dbv)) - if (db_get_ws(NULL, "SRAway", StatusModeToDbSetting(statusModes[i], "Msg"), &dbv)) - dbv.ptszVal = mir_wstrdup(GetDefaultMessage(statusModes[i])); + if (db_get_ws(NULL, "SRAway", StatusModeToDbSetting(it, "Default"), &dbv)) + if (db_get_ws(NULL, "SRAway", StatusModeToDbSetting(it, "Msg"), &dbv)) + dbv.ptszVal = mir_wstrdup(GetDefaultMessage(it)); mir_wstrcpy(dat->info[j].msg, dbv.ptszVal); mir_free(dbv.ptszVal); } diff --git a/src/core/stdclist/src/clcopts.cpp b/src/core/stdclist/src/clcopts.cpp index 7b889c2a21..932e546e52 100644 --- a/src/core/stdclist/src/clcopts.cpp +++ b/src/core/stdclist/src/clcopts.cpp @@ -149,12 +149,9 @@ static INT_PTR CALLBACK DlgProcClcMainOpts(HWND hwndDlg, UINT msg, WPARAM wParam SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_HIDEOFFLINEOPTS), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_HIDEOFFLINEOPTS), GWL_STYLE) | TVS_NOHSCROLL | TVS_CHECKBOXES); { - int i; DWORD exStyle = db_get_dw(NULL, "CLC", "ExStyle", pcli->pfnGetDefaultExStyle()); - for (i = 0; i < _countof(checkBoxToStyleEx); i++) - CheckDlgButton(hwndDlg, checkBoxToStyleEx[i].id, - (exStyle & checkBoxToStyleEx[i].flag) ^ (checkBoxToStyleEx[i].flag * - checkBoxToStyleEx[i].not) ? BST_CHECKED : BST_UNCHECKED); + for (auto &it : checkBoxToStyleEx) + CheckDlgButton(hwndDlg, it.id, (exStyle & it.flag) ^ (it.flag * it.not) ? BST_CHECKED : BST_UNCHECKED); } { UDACCEL accel[2] = { { 0, 10 }, { 2, 50 } }; @@ -242,11 +239,10 @@ static INT_PTR CALLBACK DlgProcClcMainOpts(HWND hwndDlg, UINT msg, WPARAM wParam case 0: if (((LPNMHDR)lParam)->code == PSN_APPLY) { - int i; DWORD exStyle = 0; - for (i = 0; i < _countof(checkBoxToStyleEx); i++) - if ((IsDlgButtonChecked(hwndDlg, checkBoxToStyleEx[i].id) == 0) == checkBoxToStyleEx[i].not) - exStyle |= checkBoxToStyleEx[i].flag; + for (auto &it : checkBoxToStyleEx) + if ((IsDlgButtonChecked(hwndDlg, it.id) == 0) == it.not) + exStyle |= it.flag; db_set_dw(NULL, "CLC", "ExStyle", exStyle); { diff --git a/src/core/stdclist/src/contact.cpp b/src/core/stdclist/src/contact.cpp index b3b46976a5..d03630e45b 100644 --- a/src/core/stdclist/src/contact.cpp +++ b/src/core/stdclist/src/contact.cpp @@ -44,10 +44,10 @@ static statusModeOrder[] = { int GetStatusModeOrdering(int statusMode) { - int i; - for (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/src/core/stdidle/src/options.cpp b/src/core/stdidle/src/options.cpp index a3753db6d1..e9e670fe51 100644 --- a/src/core/stdidle/src/options.cpp +++ b/src/core/stdidle/src/options.cpp @@ -94,8 +94,8 @@ public: spinIdle.SetRange(60, 1); spinIdle.SetPosition(S.iIdleTime1st); - for (int j = 0; j < _countof(aa_Status); j++) - cmbAAStatus.AddString(pcli->pfnGetStatusModeDescription(aa_Status[j], 0)); + for (auto &it : aa_Status) + cmbAAStatus.AddString(pcli->pfnGetStatusModeDescription(it, 0)); cmbAAStatus.SetCurSel(IdleGetStatusIndex(S.bAAStatus)); ShowHide(); diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 1ec5bbbd1c..58d6ecf2a7 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -500,6 +500,6 @@ void LoadMsgLogIcons(void) void FreeMsgLogIcons(void) { - for (int i = 0; i < _countof(pLogIconBmpBits); i++) - mir_free(pLogIconBmpBits[i]); + for (auto &it : pLogIconBmpBits) + mir_free(it); } diff --git a/src/core/stdmsg/src/msgoptions.cpp b/src/core/stdmsg/src/msgoptions.cpp index 79cae04ddc..34bb77028c 100644 --- a/src/core/stdmsg/src/msgoptions.cpp +++ b/src/core/stdmsg/src/msgoptions.cpp @@ -166,11 +166,11 @@ class COptionMainDlg : public CPluginDlgBase tvis.hParent = nullptr; tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE; - for (int i = 0; i < _countof(statusValues); i++) { - tvis.item.lParam = statusValues[i].style; - tvis.item.pszText = TranslateW(statusValues[i].szDescr); + for (auto &it : statusValues) { + tvis.item.lParam = it.style; + tvis.item.pszText = TranslateW(it.szDescr); tvis.item.stateMask = TVIS_STATEIMAGEMASK; - tvis.item.iImage = (style & statusValues[i].style) != 0; + tvis.item.iImage = (style & it.style) != 0; tree.InsertItem(&tvis); } } -- cgit v1.2.3