summaryrefslogtreecommitdiff
path: root/plugins/Weather/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-16 12:09:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-16 12:09:38 +0300
commita7e5e613f86963c8bf82248ab044e0ea36e42fbc (patch)
tree39e0e6b3ab4bcb55255302d3d1e989b31247bf7b /plugins/Weather/src
parentecbca42677af470d672e66d3f6950af208f8f212 (diff)
LIST<>::indexOf(T**) - fast index calculation for direct iterators
Diffstat (limited to 'plugins/Weather/src')
-rw-r--r--plugins/Weather/src/weather_data.cpp53
1 files changed, 26 insertions, 27 deletions
diff --git a/plugins/Weather/src/weather_data.cpp b/plugins/Weather/src/weather_data.cpp
index dfcfc642d2..28fa9a622d 100644
--- a/plugins/Weather/src/weather_data.cpp
+++ b/plugins/Weather/src/weather_data.cpp
@@ -408,33 +408,32 @@ void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM)
db_enum_settings(hContact, GetWeatherDataFromDB, WEATHERCONDITION, &arSettings);
// begin deleting settings
- for (int i = arSettings.getCount() - 1; i >= 0; i--) {
- char *szSetting = arSettings[i];
-
- DBVARIANT dbv;
- if (!db_get_ws(hContact, WEATHERCONDITION, szSetting, &dbv)) {
- switch (Mode) {
- case WDBM_REMOVE:
- db_unset(hContact, WEATHERCONDITION, szSetting);
- break;
-
- case WDBM_DETAILDISPLAY:
- // skip the "WeatherInfo" variable
- if (!mir_strcmp(szSetting, "WeatherInfo") || !mir_strcmp(szSetting, "Ignore") || szSetting[0] == '#')
- continue;
-
- HWND hList = GetDlgItem((HWND)wParam, IDC_DATALIST);
- LV_ITEM lvi = { 0 };
- lvi.mask = LVIF_TEXT | LVIF_PARAM;
- lvi.lParam = i;
- lvi.pszText = TranslateW(_A2T(szSetting));
- lvi.iItem = ListView_InsertItem(hList, &lvi);
- lvi.pszText = dbv.ptszVal;
- ListView_SetItemText(hList, lvi.iItem, 1, dbv.ptszVal);
- break;
- }
- db_free(&dbv);
+ auto T = arSettings.rev_iter();
+ for (auto &str : T) {
+ ptrW wszText(db_get_wsa(hContact, WEATHERCONDITION, str));
+ if (wszText == nullptr)
+ continue;
+
+ switch (Mode) {
+ case WDBM_REMOVE:
+ db_unset(hContact, WEATHERCONDITION, str);
+ break;
+
+ case WDBM_DETAILDISPLAY:
+ // skip the "WeatherInfo" variable
+ if (!mir_strcmp(str, "WeatherInfo") || !mir_strcmp(str, "Ignore") || str[0] == '#')
+ continue;
+
+ HWND hList = GetDlgItem((HWND)wParam, IDC_DATALIST);
+ LV_ITEM lvi = { 0 };
+ lvi.mask = LVIF_TEXT | LVIF_PARAM;
+ lvi.lParam = T.indexOf(&str);
+ lvi.pszText = TranslateW(_A2T(str));
+ lvi.iItem = ListView_InsertItem(hList, &lvi);
+ lvi.pszText = wszText;
+ ListView_SetItemText(hList, lvi.iItem, 1, wszText);
+ break;
}
- mir_free(szSetting);
+ mir_free(str);
}
}