diff options
author | George Hazan <george.hazan@gmail.com> | 2013-07-20 20:30:07 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-07-20 20:30:07 +0000 |
commit | 5756772ef9e9fd5b4a730d8a16737996cbec55f5 (patch) | |
tree | b154b3f9e56ceb86b3385d0f59d7341f5ac9b71e /protocols/JabberG/src/jabber_list.cpp | |
parent | 2a60812b64635ecd655131217f9cb0fa077575dc (diff) |
less cycles, simplier code
git-svn-id: http://svn.miranda-ng.org/main/trunk@5434 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG/src/jabber_list.cpp')
-rw-r--r-- | protocols/JabberG/src/jabber_list.cpp | 60 |
1 files changed, 25 insertions, 35 deletions
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 67ab77fcf1..aaf41f912b 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -195,7 +195,7 @@ int CJabberProto::ListFindNext(JABBER_LIST list, int fromOffset) {
mir_cslock lck(m_csLists);
int i = (fromOffset >= 0) ? fromOffset : 0;
- for (; i<m_lstRoster.getCount(); i++)
+ for (; i < m_lstRoster.getCount(); i++)
if (m_lstRoster[i]->list == list)
return i;
@@ -205,6 +205,18 @@ int CJabberProto::ListFindNext(JABBER_LIST list, int fromOffset) /////////////////////////////////////////////////////////////////////////////////////////
// Resource related code
+JABBER_RESOURCE_STATUS* JABBER_LIST_ITEM::findResource(const TCHAR *resourceName) const
+{
+ if (pResources == NULL || resourceName == NULL || *resourceName == 0)
+ return NULL;
+
+ for (int i=0; i < resourceCount; i++)
+ if ( !_tcscmp(pResources[i].resourceName, resourceName))
+ return pResources + i;
+
+ return NULL;
+}
+
JABBER_RESOURCE_STATUS* CJabberProto::ListFindResource(JABBER_LIST list, const TCHAR *jid)
{
mir_cslock lck(m_csLists);
@@ -214,16 +226,7 @@ JABBER_RESOURCE_STATUS* CJabberProto::ListFindResource(JABBER_LIST list, const T const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
- if (q == NULL)
- return NULL;
-
- const TCHAR *resource = q+1;
- if (*resource)
- for (int j=0; j < LI->resourceCount; j++)
- if ( !_tcscmp(LI->pResources[j].resourceName, resource))
- return LI->pResources + j;
-
- return NULL;
+ return (q == NULL) ? NULL : LI->findResource(q+1);
}
int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status, const TCHAR *statusMessage, char priority, const TCHAR *nick)
@@ -233,26 +236,21 @@ int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status if (LI == NULL)
return NULL;
- int bIsNewResource = false, j;
+ bool bIsNewResource = false;
const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
if (q) {
const TCHAR *resource = q+1;
if (resource[0]) {
- JABBER_RESOURCE_STATUS *r = LI->pResources;
- for (j=0; j < LI->resourceCount; j++, r++) {
- if ( !_tcscmp(r->resourceName, resource)) {
- // Already exist, update status and statusMessage
- r->status = status;
- replaceStrT(r->statusMessage, statusMessage);
- r->priority = priority;
- break;
- } }
-
- if (j >= LI->resourceCount) {
- // Not already exist, add new resource
- LI->pResources = (JABBER_RESOURCE_STATUS *) mir_realloc(LI->pResources, (LI->resourceCount+1)*sizeof(JABBER_RESOURCE_STATUS));
+ JABBER_RESOURCE_STATUS *r = LI->findResource(resource);
+ if (r != NULL) { // Already exists, update status and statusMessage
+ r->status = status;
+ replaceStrT(r->statusMessage, statusMessage);
+ r->priority = priority;
+ }
+ else { // Does not exist, add new resource
+ LI->pResources = (JABBER_RESOURCE_STATUS *)mir_realloc(LI->pResources, (LI->resourceCount+1)*sizeof(JABBER_RESOURCE_STATUS));
bIsNewResource = true;
r = LI->pResources + LI->resourceCount++;
memset(r, 0, sizeof(JABBER_RESOURCE_STATUS));
@@ -290,16 +288,8 @@ void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid) if (q == NULL)
return;
- const TCHAR *resource = q+1;
- if (resource[0] == 0)
- return;
-
- JABBER_RESOURCE_STATUS *r = LI->pResources;
- for (int j=0; j < LI->resourceCount; j++, r++)
- if ( !_tcsicmp(r->resourceName, resource))
- break;
-
- if (r >= LI->pResources + LI->resourceCount)
+ JABBER_RESOURCE_STATUS *r = LI->findResource(q+1);
+ if (r == NULL)
return;
// Found last seen resource ID to be removed
|