diff options
author | George Hazan <ghazan@miranda.im> | 2018-03-16 12:09:30 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-03-16 12:09:38 +0300 |
commit | a7e5e613f86963c8bf82248ab044e0ea36e42fbc (patch) | |
tree | 39e0e6b3ab4bcb55255302d3d1e989b31247bf7b /protocols/JabberG | |
parent | ecbca42677af470d672e66d3f6950af208f8f212 (diff) |
LIST<>::indexOf(T**) - fast index calculation for direct iterators
Diffstat (limited to 'protocols/JabberG')
-rw-r--r-- | protocols/JabberG/src/jabber_frame.cpp | 32 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_list.cpp | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_menu.cpp | 5 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_opttree.cpp | 12 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_treelist.cpp | 7 |
5 files changed, 29 insertions, 33 deletions
diff --git a/protocols/JabberG/src/jabber_frame.cpp b/protocols/JabberG/src/jabber_frame.cpp index 9253442816..6f15bf4780 100644 --- a/protocols/JabberG/src/jabber_frame.cpp +++ b/protocols/JabberG/src/jabber_frame.cpp @@ -190,9 +190,9 @@ LRESULT CJabberInfoFrame::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDOWN:
{
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
- for (int i=0; i < m_pItems.getCount(); i++)
- if (m_pItems[i].m_onEvent && PtInRect(&m_pItems[i].m_rcItem, pt)) {
- m_clickedItem = i;
+ for (auto &it : m_pItems)
+ if (it->m_onEvent && PtInRect(&it->m_rcItem, pt)) {
+ m_clickedItem = m_pItems.indexOf(&it);
return 0;
}
}
@@ -339,19 +339,17 @@ void CJabberInfoFrame::PaintCompact(HDC hdc) int cy_icon = GetSystemMetrics(SM_CYSMICON);
int cx = rc.right - cx_icon - SZ_FRAMEPADDING;
- for (int i = m_pItems.getCount(); i--;) {
- CJabberInfoFrameItem &item = m_pItems[i];
-
- SetRect(&item.m_rcItem, 0, 0, 0, 0);
- if (!item.m_bShow) continue;
- if (!item.m_bCompact) continue;
+ for (auto &it : m_pItems.rev_iter()) {
+ SetRect(&it->m_rcItem, 0, 0, 0, 0);
+ if (!it->m_bShow) continue;
+ if (!it->m_bCompact) continue;
int depth = 0;
- for (char *p = item.m_pszName; p = strchr(p+1, '/'); ++depth) ;
+ for (char *p = it->m_pszName; p = strchr(p+1, '/'); ++depth) ;
if (depth == 0) {
- if (item.m_hIcolibIcon) {
- HICON hIcon = IcoLib_GetIconByHandle(item.m_hIcolibIcon);
+ if (it->m_hIcolibIcon) {
+ HICON hIcon = IcoLib_GetIconByHandle(it->m_hIcolibIcon);
if (hIcon) {
DrawIconEx(hdc, SZ_FRAMEPADDING, (rc.bottom-cy_icon)/2, hIcon, cx_icon, cy_icon, 0, nullptr, DI_NORMAL);
IcoLib_ReleaseIcon(hIcon);
@@ -359,19 +357,19 @@ void CJabberInfoFrame::PaintCompact(HDC hdc) }
RECT rcText; SetRect(&rcText, cx_icon + SZ_FRAMEPADDING + SZ_ICONSPACING, 0, rc.right - SZ_FRAMEPADDING, rc.bottom);
- DrawText(hdc, item.m_pszText, -1, &rcText, DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
+ DrawText(hdc, it->m_pszText, -1, &rcText, DT_NOPREFIX | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
}
else {
- if (item.m_hIcolibIcon) {
- HICON hIcon = IcoLib_GetIconByHandle(item.m_hIcolibIcon);
+ if (it->m_hIcolibIcon) {
+ HICON hIcon = IcoLib_GetIconByHandle(it->m_hIcolibIcon);
if (hIcon) {
- SetRect(&item.m_rcItem, cx, (rc.bottom-cy_icon)/2, cx+cx_icon, (rc.bottom-cy_icon)/2+cy_icon);
+ SetRect(&it->m_rcItem, cx, (rc.bottom-cy_icon)/2, cx+cx_icon, (rc.bottom-cy_icon)/2+cy_icon);
DrawIconEx(hdc, cx, (rc.bottom-cy_icon)/2, hIcon, cx_icon, cy_icon, 0, nullptr, DI_NORMAL);
cx -= cx_icon;
IcoLib_ReleaseIcon(hIcon);
- SetToolTip(item.m_tooltipId, &item.m_rcItem, item.m_pszText);
+ SetToolTip(it->m_tooltipId, &it->m_rcItem, it->m_pszText);
}
}
}
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 0d102bf196..8a4b817965 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -362,13 +362,11 @@ pResourceStatus JABBER_LIST_ITEM::getBestResource() const return m_pManualResource;
int nBestPos = -1, nBestPri = -200;
- for (int i = 0; i < arResources.getCount(); i++) {
- JABBER_RESOURCE_STATUS *r = arResources[i];
+ for (auto &r : arResources)
if (r->m_iPriority > nBestPri) {
nBestPri = r->m_iPriority;
- nBestPos = i;
+ nBestPos = arResources.indexOf(&r);
}
- }
return (nBestPos != -1) ? arResources[nBestPos] : nullptr;
}
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 02fc077c4f..9e0c556ba1 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -1067,11 +1067,10 @@ CJabberProto* JabberChooseInstance(bool bIsLink) return it;
int nItems = 0, lastItemId = 0;
- for (int i = 0; i < g_Instances.getCount(); i++) {
- CJabberProto *ppro = g_Instances[i];
+ for (auto &ppro : g_Instances) {
if (ppro->m_iStatus != ID_STATUS_OFFLINE && ppro->m_iStatus != ID_STATUS_CONNECTING) {
++nItems;
- lastItemId = i + 1;
+ lastItemId = g_Instances.indexOf(&ppro) + 1;
Menu_ModifyItem(ppro->m_hChooseMenuItem, nullptr, Skin_LoadProtoIcon(ppro->m_szModuleName, ppro->m_iStatus));
}
else Menu_ShowItem(ppro->m_hChooseMenuItem, false);
diff --git a/protocols/JabberG/src/jabber_opttree.cpp b/protocols/JabberG/src/jabber_opttree.cpp index c9ad4ba465..d4b0bfca13 100644 --- a/protocols/JabberG/src/jabber_opttree.cpp +++ b/protocols/JabberG/src/jabber_opttree.cpp @@ -107,12 +107,12 @@ void CCtrlTreeOpts::OnInit() SetImageList(hImgLst, TVSIL_NORMAL);
/* build options tree. based on code from IcoLib */
- for (int i = 0; i < m_options.getCount(); i++) {
+ for (auto &it : m_options) {
wchar_t *sectionName;
int sectionLevel = 0;
HTREEITEM hSection = nullptr;
- mir_wstrcpy(itemName, m_options[i]->m_szOptionName);
+ mir_wstrcpy(itemName, it->m_szOptionName);
sectionName = itemName;
while (sectionName) {
@@ -142,18 +142,18 @@ void CCtrlTreeOpts::OnInit() tvis.item.iImage = tvis.item.iSelectedImage = IMG_GRPOPEN;
}
else {
- tvis.item.lParam = i;
+ tvis.item.lParam = m_options.indexOf(&it);
- BYTE val = *m_options[i]->m_option;
+ BYTE val = *it->m_option;
- if (m_options[i]->m_groupId == OPTTREE_CHECK)
+ if (it->m_groupId == OPTTREE_CHECK)
tvis.item.iImage = tvis.item.iSelectedImage = val ? IMG_CHECK : IMG_NOCHECK;
else
tvis.item.iImage = tvis.item.iSelectedImage = val ? IMG_RCHECK : IMG_NORCHECK;
}
hItem = InsertItem(&tvis);
if (!sectionName)
- m_options[i]->m_hItem = hItem;
+ it->m_hItem = hItem;
}
}
sectionLevel++;
diff --git a/protocols/JabberG/src/jabber_treelist.cpp b/protocols/JabberG/src/jabber_treelist.cpp index 7a960fedd4..e701c79f60 100644 --- a/protocols/JabberG/src/jabber_treelist.cpp +++ b/protocols/JabberG/src/jabber_treelist.cpp @@ -320,8 +320,9 @@ void TreeList_Update(HWND hwnd) if (data->mode == TLM_TREE)
TreeList_RecursiveApply(hItem, sttTreeList_CreateItems, (LPARAM)hwnd);
else {
- for (int i = data->hItemSelected->subItems.getCount(); i--;)
- sttTreeList_CreateItems_List(data->hItemSelected->subItems[i], (LPARAM)hwnd);
+ for (auto &it : data->hItemSelected->subItems)
+ sttTreeList_CreateItems_List(it, (LPARAM)hwnd);
+
for (HTREELISTITEM p = data->hItemSelected; !(p->flags & TLIF_ROOT); p = p->parent)
sttTreeList_CreateItems_List(p, (LPARAM)hwnd);
}
@@ -504,7 +505,7 @@ static void sttTreeList_ResetIndex(HTREELISTITEM hItem, LPARAM data) static void sttTreeList_FilterItems(HTREELISTITEM hItem, LPARAM data)
{
- int i = 0;
+ int i;
for (i=0; i < hItem->text.getCount(); i++)
if (JabberStrIStr(hItem->text[i], (wchar_t *)data))
break;
|