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/MenuItemEx/src/main.cpp | 24 ++++++++++++------------ plugins/MenuItemEx/src/options.cpp | 20 +++++++------------- 2 files changed, 19 insertions(+), 25 deletions(-) (limited to 'plugins/MenuItemEx/src') diff --git a/plugins/MenuItemEx/src/main.cpp b/plugins/MenuItemEx/src/main.cpp index e77177358f..f6238d5cfb 100644 --- a/plugins/MenuItemEx/src/main.cpp +++ b/plugins/MenuItemEx/src/main.cpp @@ -289,16 +289,16 @@ int StatusMsgExists(MCONTACT hContact) LPSTR module = GetContactProto(hContact); if (!module) return 0; - for (int i = 0; i < _countof(statusMsg); i++) { - if (statusMsg[i].flag & 8) - mir_snprintf(par, "%s/%s", module, statusMsg[i].name); + for (auto &it : statusMsg) { + if (it.flag & 8) + mir_snprintf(par, "%s/%s", module, it.name); else - strncpy(par, statusMsg[i].name, _countof(par)-1); + strncpy(par, it.name, _countof(par)-1); - LPSTR msg = db_get_sa(hContact, (statusMsg[i].module) ? statusMsg[i].module : module, par); + LPSTR msg = db_get_sa(hContact, (it.module) ? it.module : module, par); if (msg) { if (mir_strlen(msg)) - ret |= statusMsg[i].flag; + ret |= it.flag; mir_free(msg); } } @@ -609,17 +609,17 @@ static INT_PTR onCopyStatusMsg(WPARAM wparam, LPARAM lparam) return 0; buffer[0] = 0; - for (int i = 0; i < _countof(statusMsg); i++) { - if (statusMsg[i].flag & 8) - mir_snprintf(par, "%s/%s", module, statusMsg[i].name); + for (auto &it : statusMsg) { + if (it.flag & 8) + mir_snprintf(par, "%s/%s", module, it.name); else - strncpy(par, statusMsg[i].name, _countof(par) - 1); + strncpy(par, it.name, _countof(par) - 1); - LPTSTR msg = db_get_wsa(hContact, (statusMsg[i].module) ? statusMsg[i].module : module, par); + LPTSTR msg = db_get_wsa(hContact, (it.module) ? it.module : module, par); if (msg) { if (wcslen(msg)) { if (flags & VF_SMNAME) { - mir_wstrncat(buffer, TranslateW(statusMsg[i].fullName), (_countof(buffer) - wcslen(buffer) - 1)); + mir_wstrncat(buffer, TranslateW(it.fullName), (_countof(buffer) - wcslen(buffer) - 1)); mir_wstrncat(buffer, L": ", (_countof(buffer) - wcslen(buffer) - 1)); } mir_wstrncat(buffer, msg, (_countof(buffer) - wcslen(buffer) - 1)); diff --git a/plugins/MenuItemEx/src/options.cpp b/plugins/MenuItemEx/src/options.cpp index 997bc2d417..853fdb40d8 100644 --- a/plugins/MenuItemEx/src/options.cpp +++ b/plugins/MenuItemEx/src/options.cpp @@ -35,25 +35,19 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) switch (msg) { case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - for (i = 0; i < _countof(checkboxes); i++) - { - CheckDlgButton(hdlg, checkboxes[i].idc, (flags & checkboxes[i].flag) ? BST_CHECKED : BST_UNCHECKED); - } + for (auto &it : checkboxes) + CheckDlgButton(hdlg, it.idc, (flags & it.flag) ? BST_CHECKED : BST_UNCHECKED); - if (bPopupService) - { - for (i = 0; i < 4; i++) - { + if (bPopupService) { + for (i = 0; i < 4; i++) { GetDlgItemText(hdlg, checkboxes[i].idc, buffer, (_countof(buffer) - 3)); mir_wstrcat(buffer, L" *"); SetDlgItemText(hdlg, checkboxes[i].idc, buffer); } } - else - ShowWindow(GetDlgItem(hdlg, IDC_HINT1), SW_HIDE); + else ShowWindow(GetDlgItem(hdlg, IDC_HINT1), SW_HIDE); SendMessage(hdlg, WM_USER + 50, 0, 0); return 0; @@ -72,8 +66,8 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) case PSN_APPLY: DWORD mod_flags = 0; - for (i = 0; i < _countof(checkboxes); i++) - mod_flags |= IsDlgButtonChecked(hdlg, checkboxes[i].idc) ? checkboxes[i].flag : 0; + for (auto &it : checkboxes) + mod_flags |= IsDlgButtonChecked(hdlg, it.idc) ? it.flag : 0; db_set_dw(NULL, MODULENAME, "flags", mod_flags); return 1; -- cgit v1.2.3