diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-20 12:48:13 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-02-20 12:48:13 +0000 |
commit | d363c51d46ee4cd1775ea5b28a50b80175e25dcc (patch) | |
tree | 633673262bd2cbf8dfbd2010ce8cc99b2711626a /plugins/Dbx_mdb/src | |
parent | f764743b3f58209720f3c9d97884f05eed642150 (diff) |
dbx_lmdb: speed optimization
git-svn-id: http://svn.miranda-ng.org/main/trunk@16314 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dbx_mdb/src')
-rw-r--r-- | plugins/Dbx_mdb/src/dbcontacts.cpp | 4 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbevents.cpp | 24 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.cpp | 16 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbintf.h | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbmodulechain.cpp | 2 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/dbsettings.cpp | 4 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/lmdb/mdb.c | 1 | ||||
-rw-r--r-- | plugins/Dbx_mdb/src/stdafx.h | 23 |
8 files changed, 42 insertions, 34 deletions
diff --git a/plugins/Dbx_mdb/src/dbcontacts.cpp b/plugins/Dbx_mdb/src/dbcontacts.cpp index c9e549da8e..cee0d1dedf 100644 --- a/plugins/Dbx_mdb/src/dbcontacts.cpp +++ b/plugins/Dbx_mdb/src/dbcontacts.cpp @@ -175,8 +175,8 @@ void CDbxMdb::GatherContactHistory(MCONTACT hContact, LIST<EventItem> &list) DBEventSortingKey keyVal = { 0, 0, hContact };
MDB_val key = { sizeof(keyVal), &keyVal }, data;
- txn_ptr_ro trnlck(m_pMdbEnv);
- cursor_ptr cursor(trnlck, m_dbEventsSort);
+ txn_ptr_ro trnlck(m_txn);
+ cursor_ptr_ro cursor(m_curEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET);
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS) {
DBEventSortingKey *pKey = (DBEventSortingKey*)key.mv_data;
diff --git a/plugins/Dbx_mdb/src/dbevents.cpp b/plugins/Dbx_mdb/src/dbevents.cpp index 39ec4d4afb..0214a3f2d8 100644 --- a/plugins/Dbx_mdb/src/dbevents.cpp +++ b/plugins/Dbx_mdb/src/dbevents.cpp @@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
-MDB_txn* txn_ptr_ro::m_txn;
-
STDMETHODIMP_(LONG) CDbxMdb::GetEventCount(MCONTACT contactID)
{
DBCachedContact *cc = m_cache->GetCachedContact(contactID);
@@ -188,7 +186,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::DeleteEvent(MCONTACT contactID, MEVENT hDbEvent) STDMETHODIMP_(LONG) CDbxMdb::GetBlobSize(MEVENT hDbEvent)
{
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
@@ -207,7 +205,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei) }
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
@@ -307,7 +305,7 @@ STDMETHODIMP_(MCONTACT) CDbxMdb::GetEventContact(MEVENT hDbEvent) if (hDbEvent == 0) return INVALID_CONTACT_ID;
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
MDB_val key = { sizeof(MEVENT), &hDbEvent }, data;
if (mdb_get(txn, m_dbEvents, &key, &data) != MDB_SUCCESS)
@@ -323,9 +321,9 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindFirstEvent(MCONTACT contactID) MDB_val key = { sizeof(keyVal), &keyVal }, data;
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
- cursor_ptr cursor(txn, m_dbEventsSort);
+ cursor_ptr_ro cursor(m_curEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET);
if (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) != MDB_SUCCESS)
return m_evLast = 0;
@@ -347,9 +345,9 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindLastEvent(MCONTACT contactID) MDB_val key = { sizeof(keyVal), &keyVal }, data;
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
- cursor_ptr cursor(txn, m_dbEventsSort);
+ cursor_ptr_ro cursor(m_curEventsSort);
mdb_cursor_get(cursor, &key, &data, MDB_SET);
if (mdb_cursor_get(cursor, &key, &data, MDB_PREV) != MDB_SUCCESS)
return m_evLast = 0;
@@ -367,7 +365,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent DWORD ts;
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
if (m_evLast != hDbEvent) {
MDB_val key = { sizeof(MEVENT), &hDbEvent };
@@ -380,7 +378,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindNextEvent(MCONTACT contactID, MEVENT hDbEvent DBEventSortingKey keyVal = { hDbEvent, ts, contactID };
MDB_val key = { sizeof(keyVal), &keyVal };
- cursor_ptr cursor(txn, m_dbEventsSort);
+ cursor_ptr_ro cursor(m_curEventsSort);
if (mdb_cursor_get(cursor, &key, &data, MDB_SET) != MDB_SUCCESS)
return m_evLast = 0;
@@ -400,7 +398,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent DWORD ts;
mir_cslock lck(m_csDbAccess);
- txn_ptr_ro txn(m_pMdbEnv);
+ txn_ptr_ro txn(m_txn);
if (m_evLast != hDbEvent) {
MDB_val key = { sizeof(MEVENT), &hDbEvent };
@@ -413,7 +411,7 @@ STDMETHODIMP_(MEVENT) CDbxMdb::FindPrevEvent(MCONTACT contactID, MEVENT hDbEvent DBEventSortingKey keyVal = { hDbEvent, ts, contactID };
MDB_val key = { sizeof(keyVal), &keyVal };
- cursor_ptr cursor(txn, m_dbEventsSort);
+ cursor_ptr_ro cursor(m_curEventsSort);
if (mdb_cursor_get(cursor, &key, &data, MDB_SET) != MDB_SUCCESS)
return m_evLast = 0;
diff --git a/plugins/Dbx_mdb/src/dbintf.cpp b/plugins/Dbx_mdb/src/dbintf.cpp index cb044d622f..a036f5090f 100644 --- a/plugins/Dbx_mdb/src/dbintf.cpp +++ b/plugins/Dbx_mdb/src/dbintf.cpp @@ -33,11 +33,6 @@ static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2) return (mn1->ofs - mn2->ofs);
}
-static int stringCompare2(const char *p1, const char *p2)
-{
- return strcmp(p1, p2);
-}
-
CDbxMdb::CDbxMdb(const TCHAR *tszFileName, int iMode) :
m_safetyMode(true),
m_bReadOnly((iMode & DBMODE_READONLY) != 0),
@@ -45,7 +40,7 @@ CDbxMdb::CDbxMdb(const TCHAR *tszFileName, int iMode) : m_dwMaxContactId(1),
m_lMods(50, ModCompare),
m_lOfs(50, OfsCompare),
- m_lResidentSettings(50, stringCompare2)
+ m_lResidentSettings(50, strcmp)
{
m_tszProfileName = mir_tstrdup(tszFileName);
InitDbInstance(this);
@@ -98,7 +93,6 @@ int CDbxMdb::Load(bool bSkipInit) mdb_open(trnlck, "eventsrt", MDB_CREATE | MDB_INTEGERKEY, &m_dbEventsSort);
mdb_open(trnlck, "settings", MDB_CREATE, &m_dbSettings);
-
DWORD keyVal = 1;
MDB_val key = { sizeof(DWORD), &keyVal }, data;
if (mdb_get(trnlck, m_dbGlobal, &key, &data) == MDB_SUCCESS) {
@@ -121,6 +115,14 @@ int CDbxMdb::Load(bool bSkipInit) }
trnlck.commit();
+ {
+ mdb_txn_begin(m_pMdbEnv, nullptr, MDB_RDONLY, &m_txn);
+ mdb_cursor_open(m_txn, m_dbEvents, &m_curEvents);
+ mdb_cursor_open(m_txn, m_dbEventsSort, &m_curEventsSort);
+ mdb_txn_reset(m_txn);
+ }
+
+
if (InitModuleNames()) return EGROKPRF_CANTREAD;
if (InitCrypt()) return EGROKPRF_CANTREAD;
diff --git a/plugins/Dbx_mdb/src/dbintf.h b/plugins/Dbx_mdb/src/dbintf.h index d6751960b2..210bf9f785 100644 --- a/plugins/Dbx_mdb/src/dbintf.h +++ b/plugins/Dbx_mdb/src/dbintf.h @@ -234,6 +234,7 @@ public: protected:
MDB_env *m_pMdbEnv;
+ MDB_txn *m_txn;
DWORD m_dwFileSize;
MDB_dbi m_dbGlobal;
DBHeader m_header;
@@ -263,6 +264,7 @@ protected: // events
MDB_dbi m_dbEvents, m_dbEventsSort;
+ MDB_cursor *m_curEvents, *m_curEventsSort;
DWORD m_dwMaxEventId, m_tsLast;
MEVENT m_evLast;
diff --git a/plugins/Dbx_mdb/src/dbmodulechain.cpp b/plugins/Dbx_mdb/src/dbmodulechain.cpp index faff9df351..cc988e3f66 100644 --- a/plugins/Dbx_mdb/src/dbmodulechain.cpp +++ b/plugins/Dbx_mdb/src/dbmodulechain.cpp @@ -42,7 +42,7 @@ int CDbxMdb::InitModuleNames(void) {
m_maxModuleID = 0;
- txn_ptr_ro trnlck(m_pMdbEnv);
+ txn_ptr_ro trnlck(m_txn);
//mdb_open(trnlck, "modules", MDB_INTEGERKEY, &m_dbModules);
cursor_ptr cursor(trnlck, m_dbModules);
diff --git a/plugins/Dbx_mdb/src/dbsettings.cpp b/plugins/Dbx_mdb/src/dbsettings.cpp index d5ff44266b..99d99668e9 100644 --- a/plugins/Dbx_mdb/src/dbsettings.cpp +++ b/plugins/Dbx_mdb/src/dbsettings.cpp @@ -114,7 +114,7 @@ LBL_Seek: DBCachedContact *cc = (contactID) ? m_cache->GetCachedContact(contactID) : NULL;
- txn_ptr_ro trnlck(m_pMdbEnv);
+ txn_ptr_ro trnlck(m_txn);
//mdb_open(trnlck, "settings", 0, &m_dbSettings);
DBSettingKey keySearch;
@@ -586,7 +586,7 @@ STDMETHODIMP_(BOOL) CDbxMdb::EnumContactSettings(MCONTACT contactID, DBCONTACTEN LIST<char> arSettings(50);
{
- txn_ptr_ro trnlck(m_pMdbEnv);
+ txn_ptr_ro trnlck(m_txn);
cursor_ptr cursor(trnlck, m_dbSettings);
MDB_val key = { sizeof(keySearch), &keySearch }, data;
diff --git a/plugins/Dbx_mdb/src/lmdb/mdb.c b/plugins/Dbx_mdb/src/lmdb/mdb.c index 2b0bad3dd1..a8dbaa3260 100644 --- a/plugins/Dbx_mdb/src/lmdb/mdb.c +++ b/plugins/Dbx_mdb/src/lmdb/mdb.c @@ -36,6 +36,7 @@ #define _GNU_SOURCE 1 #endif #ifdef _WIN32 +#pragma warning(disable:4706) #include <malloc.h> #include <windows.h> /** getpid() returns int; MinGW defines pid_t but MinGW64 typedefs it diff --git a/plugins/Dbx_mdb/src/stdafx.h b/plugins/Dbx_mdb/src/stdafx.h index 0a777f5e5b..793c25b6f0 100644 --- a/plugins/Dbx_mdb/src/stdafx.h +++ b/plugins/Dbx_mdb/src/stdafx.h @@ -79,22 +79,16 @@ public: class txn_ptr_ro
{
- static MDB_txn *m_txn;
-
+ MDB_txn *m_txn;
public:
- __forceinline txn_ptr_ro(MDB_env *pEnv)
+ __forceinline txn_ptr_ro(MDB_txn *&txn) : m_txn(txn)
{
- if (!m_txn)
- mdb_txn_begin(pEnv, NULL, MDB_RDONLY, &m_txn);
- else
- mdb_txn_renew(m_txn);
+ mdb_txn_renew(m_txn);
}
-
__forceinline ~txn_ptr_ro()
{
mdb_txn_reset(m_txn);
}
-
__forceinline operator MDB_txn*() const { return m_txn; }
};
@@ -118,6 +112,17 @@ public: __forceinline operator MDB_cursor*() const { return m_cursor; }
};
+class cursor_ptr_ro
+{
+ MDB_cursor *m_cursor;
+public:
+ __forceinline cursor_ptr_ro(MDB_cursor *&cursor) : m_cursor(cursor)
+ {
+ mdb_cursor_renew(mdb_cursor_txn(m_cursor), m_cursor); //--
+ }
+ __forceinline operator MDB_cursor*() const { return m_cursor; }
+};
+
#define MDB_CHECK(A,B) \
switch(A) { \
case MDB_SUCCESS: break; \
|