Skip to content

Commit 07fd147

Browse files
committed
Merge #9353: Add data() method to CDataStream (and use it)
5113474 wallet: Use CDataStream.data() (Wladimir J. van der Laan) e2300ff bench: Use CDataStream.data() (Wladimir J. van der Laan) adff950 dbwrapper: Use new .data() method of CDataStream (Wladimir J. van der Laan) a2141e4 streams: Remove special cases for ancient MSVC (Wladimir J. van der Laan) af4c44c streams: Add data() method to CDataStream (Wladimir J. van der Laan)
2 parents 12e3112 + 5113474 commit 07fd147

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

src/bench/verify_script.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void VerifyScriptBench(benchmark::State& state)
9393
txCredit.vout[0].scriptPubKey.data(),
9494
txCredit.vout[0].scriptPubKey.size(),
9595
txCredit.vout[0].nValue,
96-
(const unsigned char*)&stream[0], stream.size(), 0, flags, nullptr);
96+
(const unsigned char*)stream.data(), stream.size(), 0, flags, nullptr);
9797
assert(csuccess == 1);
9898
#endif
9999
}

src/dbwrapper.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ class CDBBatch
6767
{
6868
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
6969
ssKey << key;
70-
leveldb::Slice slKey(&ssKey[0], ssKey.size());
70+
leveldb::Slice slKey(ssKey.data(), ssKey.size());
7171

7272
ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
7373
ssValue << value;
7474
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
75-
leveldb::Slice slValue(&ssValue[0], ssValue.size());
75+
leveldb::Slice slValue(ssValue.data(), ssValue.size());
7676

7777
batch.Put(slKey, slValue);
7878
ssKey.clear();
@@ -84,7 +84,7 @@ class CDBBatch
8484
{
8585
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
8686
ssKey << key;
87-
leveldb::Slice slKey(&ssKey[0], ssKey.size());
87+
leveldb::Slice slKey(ssKey.data(), ssKey.size());
8888

8989
batch.Delete(slKey);
9090
ssKey.clear();
@@ -115,7 +115,7 @@ class CDBIterator
115115
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
116116
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
117117
ssKey << key;
118-
leveldb::Slice slKey(&ssKey[0], ssKey.size());
118+
leveldb::Slice slKey(ssKey.data(), ssKey.size());
119119
piter->Seek(slKey);
120120
}
121121

@@ -208,7 +208,7 @@ class CDBWrapper
208208
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
209209
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
210210
ssKey << key;
211-
leveldb::Slice slKey(&ssKey[0], ssKey.size());
211+
leveldb::Slice slKey(ssKey.data(), ssKey.size());
212212

213213
std::string strValue;
214214
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
@@ -242,7 +242,7 @@ class CDBWrapper
242242
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
243243
ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
244244
ssKey << key;
245-
leveldb::Slice slKey(&ssKey[0], ssKey.size());
245+
leveldb::Slice slKey(ssKey.data(), ssKey.size());
246246

247247
std::string strValue;
248248
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);

src/streams.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ class CDataStream
174174
Init(nTypeIn, nVersionIn);
175175
}
176176

177-
#if !defined(_MSC_VER) || _MSC_VER >= 1300
178177
CDataStream(const char* pbegin, const char* pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
179178
{
180179
Init(nTypeIn, nVersionIn);
181180
}
182-
#endif
183181

184182
CDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
185183
{
@@ -245,6 +243,8 @@ class CDataStream
245243
void clear() { vch.clear(); nReadPos = 0; }
246244
iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); }
247245
void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); }
246+
value_type* data() { return vch.data() + nReadPos; }
247+
const value_type* data() const { return vch.data() + nReadPos; }
248248

249249
void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
250250
{
@@ -259,7 +259,6 @@ class CDataStream
259259
vch.insert(it, first, last);
260260
}
261261

262-
#if !defined(_MSC_VER) || _MSC_VER >= 1300
263262
void insert(iterator it, const char* first, const char* last)
264263
{
265264
assert(last - first >= 0);
@@ -272,7 +271,6 @@ class CDataStream
272271
else
273272
vch.insert(it, first, last);
274273
}
275-
#endif
276274

277275
iterator erase(iterator it)
278276
{

src/wallet/db.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
397397
break;
398398
}
399399
if (pszSkip &&
400-
strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0)
400+
strncmp(ssKey.data(), pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0)
401401
continue;
402-
if (strncmp(&ssKey[0], "\x07version", 8) == 0) {
402+
if (strncmp(ssKey.data(), "\x07version", 8) == 0) {
403403
// Update version:
404404
ssValue.clear();
405405
ssValue << CLIENT_VERSION;
406406
}
407-
Dbt datKey(&ssKey[0], ssKey.size());
408-
Dbt datValue(&ssValue[0], ssValue.size());
407+
Dbt datKey(ssKey.data(), ssKey.size());
408+
Dbt datValue(ssValue.data(), ssValue.size());
409409
int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE);
410410
if (ret2 > 0)
411411
fSuccess = false;

src/wallet/db.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CDB
122122
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
123123
ssKey.reserve(1000);
124124
ssKey << key;
125-
Dbt datKey(&ssKey[0], ssKey.size());
125+
Dbt datKey(ssKey.data(), ssKey.size());
126126

127127
// Read
128128
Dbt datValue;
@@ -158,13 +158,13 @@ class CDB
158158
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
159159
ssKey.reserve(1000);
160160
ssKey << key;
161-
Dbt datKey(&ssKey[0], ssKey.size());
161+
Dbt datKey(ssKey.data(), ssKey.size());
162162

163163
// Value
164164
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
165165
ssValue.reserve(10000);
166166
ssValue << value;
167-
Dbt datValue(&ssValue[0], ssValue.size());
167+
Dbt datValue(ssValue.data(), ssValue.size());
168168

169169
// Write
170170
int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE));
@@ -187,7 +187,7 @@ class CDB
187187
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
188188
ssKey.reserve(1000);
189189
ssKey << key;
190-
Dbt datKey(&ssKey[0], ssKey.size());
190+
Dbt datKey(ssKey.data(), ssKey.size());
191191

192192
// Erase
193193
int ret = pdb->del(activeTxn, &datKey, 0);
@@ -207,7 +207,7 @@ class CDB
207207
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
208208
ssKey.reserve(1000);
209209
ssKey << key;
210-
Dbt datKey(&ssKey[0], ssKey.size());
210+
Dbt datKey(ssKey.data(), ssKey.size());
211211

212212
// Exists
213213
int ret = pdb->exists(activeTxn, &datKey, 0);
@@ -234,7 +234,7 @@ class CDB
234234
Dbt datKey;
235235
unsigned int fFlags = DB_NEXT;
236236
if (setRange) {
237-
datKey.set_data(&ssKey[0]);
237+
datKey.set_data(ssKey.data());
238238
datKey.set_size(ssKey.size());
239239
fFlags = DB_SET_RANGE;
240240
}

0 commit comments

Comments
 (0)