diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-08 10:39:59 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-03-08 10:39:59 +0000 |
commit | 0bac8935f42efa1e1152fd09a04d95b76d8c5eb3 (patch) | |
tree | 93a8f9fc987ea7007b277ea27d0780999c2e8eeb /plugins/Dbx_mdb | |
parent | 90cc15799fe189134d9580c1dc121d0b78df17ba (diff) |
dbx_lmdb: more fixes & optimizations
git-svn-id: http://svn.miranda-ng.org/main/trunk@16446 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 6 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbevents.cpp | 12 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbsettings.cpp | 116 |
3 files changed, 69 insertions, 65 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index e8f72bc9c3..f19811b10e 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -120,7 +120,7 @@ STDMETHODIMP_(LONG) CDbxMdb::DeleteContact(MCONTACT contactID) do
{
- DBSettingKey *pKey = (DBSettingKey*)key.mv_data;
+ const DBSettingKey *pKey = (const DBSettingKey*)key.mv_data;
if (pKey->dwContactID != contactID)
break;
mdb_cursor_del(cursor, 0);
@@ -207,7 +207,7 @@ void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list) cursor_ptr_ro cursor(m_curEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE);
do {
- DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
if (pKey->dwContactId != hContact)
return;
@@ -322,7 +322,7 @@ void CDbxMdb::FillContacts() MDB_val key, data;
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0)
{
- DBContact *dbc = (DBContact*)data.mv_data;
+ const DBContact *dbc = (const DBContact*)data.mv_data;
if (dbc->dwSignature != DBCONTACT_SIGNATURE)
DatabaseCorruption(NULL);
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index a69b57a5bf..466cd3b452 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -215,7 +215,7 @@ STDMETHODIMP_(LONG) CDbxMdb::GetBlobSize(MEVENT hDbEvent) if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
return -1;
- DBEvent *dbe = (DBEvent*)data.mv_data;
+ const DBEvent *dbe = (const DBEvent*)data.mv_data;
return (dbe->dwSignature == DBEVENT_SIGNATURE) ? dbe->cbBlob : 0;
}
@@ -347,7 +347,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::GetEventContact(MEVENT hDbEvent) if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
return INVALID_CONTACT_ID;
- DBEvent *dbe = (DBEvent*)data.mv_data;
+ const DBEvent *dbe = (const DBEvent*)data.mv_data;
return (dbe->dwSignature == DBEVENT_SIGNATURE) ? dbe->contactID : INVALID_CONTACT_ID;
}
@@ -362,7 +362,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID) cursor_ptr_ro cursor(m_curEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE);
- DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
m_tsLast = pKey->ts;
return m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
@@ -386,7 +386,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindLastEvent(MCONTACT contactID) if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
return m_evLast = 0;
- DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
m_tsLast = pKey->ts;
return m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
@@ -420,7 +420,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS)
return m_evLast = 0;
- DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
m_tsLast = pKey->ts;
return m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
@@ -454,7 +454,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
return m_evLast = 0;
- DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
+ const DBEventSortingKey *pKey = (const DBEventSortingKey*)key.mv_data;
m_tsLast = pKey->ts;
return m_evLast = (pKey->dwContactId == contactID) ? pKey->dwEventId : 0;
}
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index 2abaaa648a..623bea9024 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -68,12 +68,15 @@ LBL_Seek: char *szCachedSettingName = m_cache->GetCachedSetting(szModule, szSetting, moduleNameLen, settingNameLen);
DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 0);
- if (pCachedValue != NULL) {
- if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8) {
+ if (pCachedValue != NULL)
+ {
+ if (pCachedValue->type == DBVT_ASCIIZ || pCachedValue->type == DBVT_UTF8)
+ {
int cbOrigLen = dbv->cchVal;
char *cbOrigPtr = dbv->pszVal;
memcpy(dbv, pCachedValue, sizeof(DBVARIANT));
- if (isStatic) {
+ if (isStatic)
+ {
int cbLen = 0;
if (pCachedValue->pszVal != NULL)
cbLen = (int)strlen(pCachedValue->pszVal);
@@ -86,7 +89,8 @@ LBL_Seek: dbv->pszVal[cbOrigLen] = 0;
dbv->cchVal = cbLen;
}
- else {
+ else
+ {
dbv->pszVal = (char*)mir_alloc(strlen(pCachedValue->pszVal) + 1);
strcpy(dbv->pszVal, pCachedValue->pszVal);
}
@@ -103,19 +107,20 @@ LBL_Seek: DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
txn_ptr_ro trnlck(m_txn);
- //mdb_open(trnlck, "settings", 0, &m_dbSettings);
- DBSettingKey keySearch;
- keySearch.dwContactID = contactID;
- keySearch.dwOfsModule = GetModuleNameOfs(szModule);
+ DBSettingKey keySearch = { contactID, GetModuleNameOfs(szModule) };
strncpy_s(keySearch.szSettingName, szSetting, _TRUNCATE);
MDB_val key = { 2 * sizeof(DWORD) + settingNameLen, &keySearch }, data;
- if (mdb_get(trnlck, m_dbSettings, &key, &data)) {
+ if (mdb_get(trnlck, m_dbSettings, &key, &data) != MDB_SUCCESS)
+ {
// try to get the missing mc setting from the active sub
- if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting)) {
- if (contactID = db_mc_getDefault(contactID)) {
- if (szModule = GetContactProto(contactID)) {
+ if (cc && cc->IsMeta() && ValidLookupName(szModule, szSetting))
+ {
+ if (contactID = db_mc_getDefault(contactID))
+ {
+ if (szModule = GetContactProto(contactID))
+ {
moduleNameLen = (int)strlen(szModule);
goto LBL_Seek;
}
@@ -124,7 +129,7 @@ LBL_Seek: return 1;
}
- BYTE *pBlob = (BYTE*)data.mv_data;
+ const BYTE *pBlob = (const BYTE*)data.mv_data;
if (isStatic && (pBlob[0] & DBVTF_VARIABLELENGTH) && VLT(dbv->type) != VLT(pBlob[0]))
return 1;
@@ -143,17 +148,18 @@ LBL_Seek: case DBVT_ASCIIZ:
varLen = *(WORD*)pBlob;
pBlob += 2;
- if (isStatic) {
+ if (isStatic)
+ {
dbv->cchVal--;
if (varLen < dbv->cchVal)
dbv->cchVal = varLen;
- memmove(dbv->pszVal, pBlob, dbv->cchVal); // decode
+ memcpy(dbv->pszVal, pBlob, dbv->cchVal); // decode
dbv->pszVal[dbv->cchVal] = 0;
dbv->cchVal = varLen;
}
else {
dbv->pszVal = (char*)mir_alloc(1 + varLen);
- memmove(dbv->pszVal, pBlob, varLen);
+ memcpy(dbv->pszVal, pBlob, varLen);
dbv->pszVal[varLen] = 0;
}
break;
@@ -161,14 +167,15 @@ LBL_Seek: case DBVT_BLOB:
varLen = *(WORD*)pBlob;
pBlob += 2;
- if (isStatic) {
+ if (isStatic)
+ {
if (varLen < dbv->cpbVal)
dbv->cpbVal = varLen;
- memmove(dbv->pbVal, pBlob, dbv->cpbVal);
+ memcpy(dbv->pbVal, pBlob, dbv->cpbVal);
}
else {
dbv->pbVal = (BYTE *)mir_alloc(varLen);
- memmove(dbv->pbVal, pBlob, varLen);
+ memcpy(dbv->pbVal, pBlob, varLen);
}
dbv->cpbVal = varLen;
break;
@@ -187,17 +194,19 @@ LBL_Seek: varLen = (WORD)realLen;
dbv->type = DBVT_UTF8;
- if (isStatic) {
+ if (isStatic)
+ {
dbv->cchVal--;
if (varLen < dbv->cchVal)
dbv->cchVal = varLen;
- memmove(dbv->pszVal, decoded, dbv->cchVal);
+ memcpy(dbv->pszVal, decoded, dbv->cchVal);
dbv->pszVal[dbv->cchVal] = 0;
dbv->cchVal = varLen;
}
- else {
+ else
+ {
dbv->pszVal = (char*)mir_alloc(1 + varLen);
- memmove(dbv->pszVal, decoded, varLen);
+ memcpy(dbv->pszVal, decoded, varLen);
dbv->pszVal[varLen] = 0;
}
break;
@@ -219,10 +228,12 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetContactSetting(MCONTACT contactID, LPCSTR szModu if (GetContactSettingWorker(contactID, szModule, szSetting, dbv, 0))
return 1;
- if (dbv->type == DBVT_UTF8) {
+ if (dbv->type == DBVT_UTF8)
+ {
WCHAR *tmp = NULL;
char *p = NEWSTR_ALLOCA(dbv->pszVal);
- if (mir_utf8decode(p, &tmp) != NULL) {
+ if (mir_utf8decode(p, &tmp) != NULL)
+ {
BOOL bUsed = FALSE;
int result = WideCharToMultiByte(m_codePage, WC_NO_BEST_FIT_CHARS, tmp, -1, NULL, 0, NULL, &bUsed);
@@ -239,7 +250,8 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetContactSetting(MCONTACT contactID, LPCSTR szModu mir_free(tmp);
}
}
- else {
+ else
+ {
dbv->type = DBVT_ASCIIZ;
mir_free(tmp);
}
@@ -509,7 +521,6 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteContactSetting(MCONTACT contactID, LPCSTR szM if (!szModule || !szSetting)
return 1;
- // the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
int settingNameLen = (int)strlen(szSetting);
int moduleNameLen = (int)strlen(szModule);
@@ -525,11 +536,10 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteContactSetting(MCONTACT contactID, LPCSTR szM MDB_val key = { 2 * sizeof(DWORD) + settingNameLen, &keySearch }, data;
- for (;; Remap()) {
+ for (;; Remap())
+ {
txn_ptr trnlck(m_pMdbEnv);
- if (mdb_del(trnlck, m_dbSettings, &key, &data))
- return 1;
-
+ MDB_CHECK(mdb_del(trnlck, m_dbSettings, &key, &data), 1);
if (trnlck.commit())
break;
}
@@ -559,33 +569,27 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT contactID, DBCONTACTEN keySearch.dwOfsModule = GetModuleNameOfs(dbces->szModule);
memset(keySearch.szSettingName, 0, _countof(keySearch.szSettingName));
- LIST<char> arSettings(50);
- {
- mir_cslock lck(m_csDbAccess);
- txn_ptr_ro trnlck(m_txn);
- cursor_ptr_ro cursor(m_curSettings);
-
- MDB_val key = { sizeof(keySearch), &keySearch }, data;
- if (mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE) == MDB_SUCCESS) {
- do {
- DBSettingKey *pKey = (DBSettingKey*)key.mv_data;
- if (pKey->dwContactID != contactID || pKey->dwOfsModule != keySearch.dwOfsModule)
- break;
-
- char szSetting[256];
- strncpy_s(szSetting, pKey->szSettingName, key.mv_size - sizeof(DWORD) * 2);
- arSettings.insert(mir_strdup(szSetting));
- }
- while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
- }
- }
+ mir_cslockfull lck(m_csDbAccess);
+ txn_ptr_ro trnlck(m_txn);
+ cursor_ptr_ro cursor(m_curSettings);
- if (arSettings.getCount() == 0)
- return -1;
+ MDB_val key = { sizeof(keySearch), &keySearch }, data;
- for (int i = 0; i < arSettings.getCount(); i++) {
- result = (dbces->pfnEnumProc)(arSettings[i], dbces->lParam);
- mir_free(arSettings[i]);
+ if (mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE) == MDB_SUCCESS)
+ {
+ size_t i = 0;
+ do
+ {
+ const DBSettingKey *pKey = (const DBSettingKey*)key.mv_data;
+ if (pKey->dwContactID != contactID || pKey->dwOfsModule != keySearch.dwOfsModule)
+ return i == 0 ? -1 : result;
+
+ char szSetting[256];
+ strncpy_s(szSetting, pKey->szSettingName, key.mv_size - sizeof(DWORD) * 2);
+ result = (dbces->pfnEnumProc)(szSetting, dbces->lParam);
+ i++;
+ }
+ while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS);
}
return result;
|