17
17
#include < leveldb/db.h>
18
18
#include < leveldb/write_batch.h>
19
19
20
+ static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64 ;
21
+ static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024 ;
22
+
20
23
class dbwrapper_error : public std ::runtime_error
21
24
{
22
25
public:
@@ -60,12 +63,12 @@ class CDBBatch
60
63
void Write (const K& key, const V& value)
61
64
{
62
65
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
63
- ssKey.reserve (GetSerializeSize (ssKey, key) );
66
+ ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE );
64
67
ssKey << key;
65
68
leveldb::Slice slKey (&ssKey[0 ], ssKey.size ());
66
69
67
70
CDataStream ssValue (SER_DISK, CLIENT_VERSION);
68
- ssValue.reserve (GetSerializeSize (ssValue, value) );
71
+ ssValue.reserve (DBWRAPPER_PREALLOC_VALUE_SIZE );
69
72
ssValue << value;
70
73
ssValue.Xor (dbwrapper_private::GetObfuscateKey (parent));
71
74
leveldb::Slice slValue (&ssValue[0 ], ssValue.size ());
@@ -77,7 +80,7 @@ class CDBBatch
77
80
void Erase (const K& key)
78
81
{
79
82
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
80
- ssKey.reserve (GetSerializeSize (ssKey, key) );
83
+ ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE );
81
84
ssKey << key;
82
85
leveldb::Slice slKey (&ssKey[0 ], ssKey.size ());
83
86
@@ -107,7 +110,7 @@ class CDBIterator
107
110
108
111
template <typename K> void Seek (const K& key) {
109
112
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
110
- ssKey.reserve (GetSerializeSize (ssKey, key) );
113
+ ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE );
111
114
ssKey << key;
112
115
leveldb::Slice slKey (&ssKey[0 ], ssKey.size ());
113
116
piter->Seek (slKey);
@@ -200,7 +203,7 @@ class CDBWrapper
200
203
bool Read (const K& key, V& value) const
201
204
{
202
205
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
203
- ssKey.reserve (GetSerializeSize (ssKey, key) );
206
+ ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE );
204
207
ssKey << key;
205
208
leveldb::Slice slKey (&ssKey[0 ], ssKey.size ());
206
209
@@ -234,7 +237,7 @@ class CDBWrapper
234
237
bool Exists (const K& key) const
235
238
{
236
239
CDataStream ssKey (SER_DISK, CLIENT_VERSION);
237
- ssKey.reserve (GetSerializeSize (ssKey, key) );
240
+ ssKey.reserve (DBWRAPPER_PREALLOC_KEY_SIZE );
238
241
ssKey << key;
239
242
leveldb::Slice slKey (&ssKey[0 ], ssKey.size ());
240
243
0 commit comments