summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
commit59e6b15f513cc998ce13e9e49e2a6a3ace445ebb (patch)
treeaf52b73a17039ed1fbe398ba9f488c26a7071257 /protocols/JabberG
parentbdaa5cf8b48515af2ac39f3f3245dd1183cbad52 (diff)
LIST<> iterators:
- new method LIST::removeItem added to save a pointer to removed record; - code cleaning related to the fact that LIST::remove() shall be the last operation inside an iterator, because otherwise the reference to it will point to a record next to deleted one; - a few remaining cycles converted to iterators
Diffstat (limited to 'protocols/JabberG')
-rw-r--r--protocols/JabberG/src/jabber_frame.cpp13
-rw-r--r--protocols/JabberG/src/jabber_iq.cpp57
-rw-r--r--protocols/JabberG/src/jabber_iq.h8
3 files changed, 33 insertions, 45 deletions
diff --git a/protocols/JabberG/src/jabber_frame.cpp b/protocols/JabberG/src/jabber_frame.cpp
index 170147508c..9253442816 100644
--- a/protocols/JabberG/src/jabber_frame.cpp
+++ b/protocols/JabberG/src/jabber_frame.cpp
@@ -474,15 +474,14 @@ void CJabberInfoFrame::RemoveInfoItem(char *pszName)
{
bool bUpdate = false;
size_t length = mir_strlen(pszName);
- for (int i = 0; i < m_pItems.getCount(); i++) {
- auto &p = m_pItems[i];
- if (!strncmp(p.m_pszName, pszName, length)) {
- if (!p.m_bShow)
+ auto T = m_pItems.rev_iter();
+ for (auto &p : T) {
+ if (!strncmp(p->m_pszName, pszName, length)) {
+ if (!p->m_bShow)
--m_hiddenItemCount;
- RemoveTooltip(p.m_tooltipId);
- m_pItems.remove(i);
+ RemoveTooltip(p->m_tooltipId);
+ m_pItems.remove(T.indexOf(&p));
bUpdate = true;
- --i;
}
}
diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp
index 6474d0b5b9..2a0c5de4f0 100644
--- a/protocols/JabberG/src/jabber_iq.cpp
+++ b/protocols/JabberG/src/jabber_iq.cpp
@@ -143,7 +143,7 @@ void CJabberIqManager::ExpirerThread()
Thread_SetName("Jabber: ExpirerThread");
while (!m_bExpirerThreadShutdownRequest) {
- CJabberIqInfo *pInfo = DetouchExpired();
+ CJabberIqInfo *pInfo = DetachExpired();
if (!pInfo) {
for (int i=0; !m_bExpirerThreadShutdownRequest && (i < 10); i++)
Sleep(50);
@@ -181,14 +181,14 @@ void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo)
void CJabberIqManager::ExpireIq(int nIqId)
{
- while (CJabberIqInfo *pInfo = DetouchInfo(nIqId))
+ while (CJabberIqInfo *pInfo = DetachInfo(nIqId))
ExpireInfo(pInfo);
}
bool CJabberIqManager::ExpireByUserData(void *pUserData)
{
bool bRet = false;
- while (CJabberIqInfo *pInfo = DetouchInfo(pUserData)) {
+ while (CJabberIqInfo *pInfo = DetachInfo(pUserData)) {
ExpireInfo(pInfo);
bRet = true;
}
@@ -197,7 +197,7 @@ bool CJabberIqManager::ExpireByUserData(void *pUserData)
void CJabberIqManager::ExpireAll()
{
- while (CJabberIqInfo *pInfo = DetouchInfo())
+ while (CJabberIqInfo *pInfo = DetachInfo())
ExpireInfo(pInfo);
}
@@ -226,9 +226,9 @@ bool CJabberIqManager::DeleteHandler(CJabberIqInfo *pInfo)
// returns TRUE when pInfo found, or FALSE otherwise
mir_cslockfull lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- if (m_arIqs[i] == pInfo) {
- m_arIqs.remove(i);
+ for (auto &it : m_arIqs) {
+ if (it == pInfo) {
+ m_arIqs.removeItem(&it);
lck.unlock();
ExpireInfo(pInfo); // must expire it to allow the handler to free m_pUserData if necessary
return true;
@@ -255,7 +255,7 @@ bool CJabberIqManager::HandleIq(int nIqId, HXML pNode)
else
return false;
- CJabberIqInfo *pInfo = DetouchInfo(nIqId);
+ CJabberIqInfo *pInfo = DetachInfo(nIqId);
if (pInfo == nullptr)
return false;
@@ -285,7 +285,7 @@ bool CJabberIqManager::HandleIq(int nIqId, HXML pNode)
(ppro->*(pInfo->m_pHandler))(pNode, pInfo);
delete pInfo;
}
- while ((pInfo = DetouchInfo(nIqId)) != nullptr);
+ while ((pInfo = DetachInfo(nIqId)) != nullptr);
return true;
}
@@ -344,7 +344,7 @@ bool CJabberIqManager::HandleIqPermanent(HXML pNode)
return false;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo()
+CJabberIqInfo* CJabberIqManager::DetachInfo()
{
mir_cslock lck(m_cs);
@@ -354,48 +354,37 @@ CJabberIqInfo* CJabberIqManager::DetouchInfo()
return pInfo;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo(int nIqId)
+CJabberIqInfo* CJabberIqManager::DetachInfo(int nIqId)
{
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (pInfo->m_nIqId == nIqId) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (it->m_nIqId == nIqId)
+ return m_arIqs.removeItem(&it);
return nullptr;
}
-CJabberIqInfo* CJabberIqManager::DetouchInfo(void *pUserData)
+CJabberIqInfo* CJabberIqManager::DetachInfo(void *pUserData)
{
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (pInfo->m_pUserData == pUserData) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (it->m_pUserData == pUserData)
+ return m_arIqs.removeItem(&it);
+
return nullptr;
}
-CJabberIqInfo* CJabberIqManager::DetouchExpired()
+CJabberIqInfo* CJabberIqManager::DetachExpired()
{
DWORD dwCurrentTime = GetTickCount();
mir_cslock lck(m_cs);
- for (int i = 0; i < m_arIqs.getCount(); i++) {
- CJabberIqInfo *pInfo = m_arIqs[i];
- if (dwCurrentTime - pInfo->m_dwRequestTime > pInfo->m_dwTimeout) {
- m_arIqs.remove(i);
- return pInfo;
- }
- }
+ for (auto &it : m_arIqs)
+ if (dwCurrentTime - it->m_dwRequestTime > it->m_dwTimeout)
+ return m_arIqs.removeItem(&it);
return nullptr;
}
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h
index 7248e0606d..bc252f4119 100644
--- a/protocols/JabberG/src/jabber_iq.h
+++ b/protocols/JabberG/src/jabber_iq.h
@@ -150,10 +150,10 @@ protected:
LIST<CJabberIqInfo> m_arIqs;
OBJLIST<CJabberIqPermanentInfo> m_arHandlers;
- CJabberIqInfo* DetouchInfo();
- CJabberIqInfo* DetouchInfo(int nIqId);
- CJabberIqInfo* DetouchInfo(void *pUserData);
- CJabberIqInfo* DetouchExpired();
+ CJabberIqInfo* DetachInfo();
+ CJabberIqInfo* DetachInfo(int nIqId);
+ CJabberIqInfo* DetachInfo(void *pUserData);
+ CJabberIqInfo* DetachExpired();
void ExpireInfo(CJabberIqInfo *pInfo);