summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-12-21 14:52:52 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-12-21 14:52:52 +0000
commit6e06694f2fdda33eb3237fe1a3aa7f6df94ad61c (patch)
treeb63b77d66f136386786a80d6b30ce601a8ee7a2f /src
parent3986b91d0e344e11b5953657fa1fb3e85d6da869 (diff)
- more effective binary search of MUUIDs;
- fix to prevent a loop creation if one forgets about UNSET_UID; git-svn-id: http://svn.miranda-ng.org/main/trunk@15926 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/menu_utils.cpp64
-rw-r--r--src/mir_core/src/utils.cpp2
2 files changed, 33 insertions, 33 deletions
diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp
index 3d6d498883..5572157cad 100644
--- a/src/mir_app/src/menu_utils.cpp
+++ b/src/mir_app/src/menu_utils.cpp
@@ -967,9 +967,7 @@ void ScheduleMenuUpdate()
static int sttFindMenuItemByUid(TMO_IntMenuItem *pimi, void *pUid)
{
- char szUid[33];
- bin2hex(&pimi->mi.uid, sizeof(MUUID), szUid);
- return !strcmp(szUid, (char*)pUid);
+ return 0 == memcmp(&pimi->mi.uid, pUid, sizeof(MUUID));
}
int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule)
@@ -988,21 +986,25 @@ int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule)
TCHAR *ptszToken = szValue, *pDelim = _tcschr(szValue, ';');
int bVisible = true, pos = 0;
TCHAR tszCustomName[201]; tszCustomName[0] = 0;
- char szCustomRoot[33]; szCustomRoot[0] = 0;
+ MUUID customRoot = {};
for (int i = 0; i < 4; i++) {
if (pDelim)
*pDelim = 0;
switch (i) {
- case 0: bVisible = _ttoi(ptszToken); break;
- case 1: pos = _ttoi(ptszToken); break;
- case 2: strncpy_s(szCustomRoot, _T2A(ptszToken), _TRUNCATE); break;
+ case 0: bVisible = _ttoi(ptszToken); break;
+ case 1: pos = _ttoi(ptszToken); break;
+ case 2:
+ hex2binT(ptszToken, &customRoot, sizeof(customRoot));
+ if (customRoot == pimi->mi.uid) // prevent a loop
+ memset(&customRoot, 0, sizeof(customRoot));
+ break;
}
ptszToken = pDelim + 1;
if ((pDelim = _tcschr(ptszToken, ';')) == NULL) {
if (i == 2 && *ptszToken != 0)
- _tcsncpy_s(tszCustomName, ptszToken, _TRUNCATE); break;
+ _tcsncpy_s(tszCustomName, ptszToken, _TRUNCATE);
break;
}
}
@@ -1017,32 +1019,30 @@ int Menu_LoadFromDatabase(TMO_IntMenuItem *pimi, void *szModule)
if (tszCustomName[0])
replaceStrT(pimi->ptszCustomName, tszCustomName);
- if (szCustomRoot[0]) {
- char szCurrentUid[33];
- if (pimi->mi.root == NULL)
- szCurrentUid[0] = 0;
- else
- bin2hex(&pimi->mi.root->mi.uid, sizeof(pimi->mi.root->mi.uid), szCurrentUid);
+ MUUID currentUid;
+ if (pimi->mi.root == NULL)
+ memset(&currentUid, 0, sizeof(currentUid));
+ else
+ memcpy(&currentUid, &pimi->mi.root->mi.uid, sizeof(currentUid));
- if (0 != strcmp(szCurrentUid, szCustomRoot)) { // need to move menu item to another root
- TMO_LinkedList *pNew;
- if (szCustomRoot[0] != 0) {
- TMO_IntMenuItem *p = MO_RecursiveWalkMenu(pmo->m_items.first, sttFindMenuItemByUid, &szCustomRoot);
- if (p == NULL)
- return NULL;
-
- pimi->mi.root = p;
- pNew = &p->submenu;
- }
- else {
- pimi->mi.root = NULL;
- pNew = &pmo->m_items;
- }
-
- // relink menu item
- pimi->owner->remove(pimi);
- pNew->insert(pimi);
+ if (currentUid != customRoot) { // need to move menu item to another root
+ TMO_LinkedList *pNew;
+ if (customRoot != miid_last) {
+ TMO_IntMenuItem *p = MO_RecursiveWalkMenu(pmo->m_items.first, sttFindMenuItemByUid, &customRoot);
+ if (p == NULL)
+ return 0;
+
+ pimi->mi.root = p;
+ pNew = &p->submenu;
+ }
+ else {
+ pimi->mi.root = NULL;
+ pNew = &pmo->m_items;
}
+
+ // relink menu item
+ pimi->owner->remove(pimi);
+ pNew->insert(pimi);
}
return 0;
diff --git a/src/mir_core/src/utils.cpp b/src/mir_core/src/utils.cpp
index a2f1ab0171..d065e8fa1b 100644
--- a/src/mir_core/src/utils.cpp
+++ b/src/mir_core/src/utils.cpp
@@ -317,7 +317,7 @@ MIR_CORE_DLL(bool) hex2binW(const wchar_t *pSrc, void *pData, size_t len)
if (pSrc == NULL || pData == NULL || len == 0)
return false;
- size_t bufLen = wcslen(pSrc);
+ size_t bufLen = wcslen(pSrc)/2;
if (pSrc[bufLen * 2] != 0 || bufLen > len)
return false;