From af4c44ce59aa643b3e03eaa121ec075f524227a5 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:15:34 +0100 Subject: [PATCH 1/5] streams: Add data() method to CDataStream Analogous to c++11 vector data(). --- src/streams.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/streams.h b/src/streams.h index b50878423..375506998 100644 --- a/src/streams.h +++ b/src/streams.h @@ -245,6 +245,8 @@ public: void clear() { vch.clear(); nReadPos = 0; } iterator insert(iterator it, const char& x=char()) { return vch.insert(it, x); } void insert(iterator it, size_type n, const char& x) { vch.insert(it, n, x); } + value_type* data() { return vch.data() + nReadPos; } + const value_type* data() const { return vch.data() + nReadPos; } void insert(iterator it, std::vector::const_iterator first, std::vector::const_iterator last) { From a2141e415aed26bab756220d8707b5fb33e6fef8 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:17:42 +0100 Subject: [PATCH 2/5] streams: Remove special cases for ancient MSVC Quite sure that we haven't supported MSVC 6.0 for ages (MSC_VER 1300 is >= MSVC++ 7.0) but with the C++11 switch we can be sure. --- src/streams.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/streams.h b/src/streams.h index 375506998..460506811 100644 --- a/src/streams.h +++ b/src/streams.h @@ -174,12 +174,10 @@ public: Init(nTypeIn, nVersionIn); } -#if !defined(_MSC_VER) || _MSC_VER >= 1300 CDataStream(const char* pbegin, const char* pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend) { Init(nTypeIn, nVersionIn); } -#endif CDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end()) { @@ -261,7 +259,6 @@ public: vch.insert(it, first, last); } -#if !defined(_MSC_VER) || _MSC_VER >= 1300 void insert(iterator it, const char* first, const char* last) { assert(last - first >= 0); @@ -274,7 +271,6 @@ public: else vch.insert(it, first, last); } -#endif iterator erase(iterator it) { From adff950faeea95249df5f7536159701ea2202255 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:22:03 +0100 Subject: [PATCH 3/5] dbwrapper: Use new .data() method of CDataStream --- src/dbwrapper.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 4a79bbd17..c5e92e01f 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -65,13 +65,13 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); CDataStream ssValue(SER_DISK, CLIENT_VERSION); ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE); ssValue << value; ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent)); - leveldb::Slice slValue(&ssValue[0], ssValue.size()); + leveldb::Slice slValue(ssValue.data(), ssValue.size()); batch.Put(slKey, slValue); } @@ -82,7 +82,7 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); batch.Delete(slKey); } @@ -112,7 +112,7 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); piter->Seek(slKey); } @@ -205,7 +205,7 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); std::string strValue; leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); @@ -239,7 +239,7 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(DBWRAPPER_PREALLOC_KEY_SIZE); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); std::string strValue; leveldb::Status status = pdb->Get(readoptions, slKey, &strValue); From e2300ff65e380bfe1454d0ea42a88abeeb6b8911 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:30:17 +0100 Subject: [PATCH 4/5] bench: Use CDataStream.data() --- src/bench/verify_script.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bench/verify_script.cpp b/src/bench/verify_script.cpp index 91b8c4447..d5fdeb731 100644 --- a/src/bench/verify_script.cpp +++ b/src/bench/verify_script.cpp @@ -94,7 +94,7 @@ static void VerifyScriptBench(benchmark::State& state) txCredit.vout[0].scriptPubKey.data(), txCredit.vout[0].scriptPubKey.size(), txCredit.vout[0].nValue, - (const unsigned char*)&stream[0], stream.size(), 0, flags, nullptr); + (const unsigned char*)stream.data(), stream.size(), 0, flags, nullptr); assert(csuccess == 1); #endif } From 5113474a91b8dcac4de0e4566b9babd5da281f29 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:34:59 +0100 Subject: [PATCH 5/5] wallet: Use CDataStream.data() --- src/wallet/db.cpp | 8 ++++---- src/wallet/db.h | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index a809c9ad6..5ff3ea3cc 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -397,15 +397,15 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) break; } if (pszSkip && - strncmp(&ssKey[0], pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0) + strncmp(ssKey.data(), pszSkip, std::min(ssKey.size(), strlen(pszSkip))) == 0) continue; - if (strncmp(&ssKey[0], "\x07version", 8) == 0) { + if (strncmp(ssKey.data(), "\x07version", 8) == 0) { // Update version: ssValue.clear(); ssValue << CLIENT_VERSION; } - Dbt datKey(&ssKey[0], ssKey.size()); - Dbt datValue(&ssValue[0], ssValue.size()); + Dbt datKey(ssKey.data(), ssKey.size()); + Dbt datValue(ssValue.data(), ssValue.size()); int ret2 = pdbCopy->put(NULL, &datKey, &datValue, DB_NOOVERWRITE); if (ret2 > 0) fSuccess = false; diff --git a/src/wallet/db.h b/src/wallet/db.h index a0f673ecf..049a2ca1a 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -122,7 +122,7 @@ protected: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - Dbt datKey(&ssKey[0], ssKey.size()); + Dbt datKey(ssKey.data(), ssKey.size()); // Read Dbt datValue; @@ -158,13 +158,13 @@ protected: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - Dbt datKey(&ssKey[0], ssKey.size()); + Dbt datKey(ssKey.data(), ssKey.size()); // Value CDataStream ssValue(SER_DISK, CLIENT_VERSION); ssValue.reserve(10000); ssValue << value; - Dbt datValue(&ssValue[0], ssValue.size()); + Dbt datValue(ssValue.data(), ssValue.size()); // Write int ret = pdb->put(activeTxn, &datKey, &datValue, (fOverwrite ? 0 : DB_NOOVERWRITE)); @@ -187,7 +187,7 @@ protected: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - Dbt datKey(&ssKey[0], ssKey.size()); + Dbt datKey(ssKey.data(), ssKey.size()); // Erase int ret = pdb->del(activeTxn, &datKey, 0); @@ -207,7 +207,7 @@ protected: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(1000); ssKey << key; - Dbt datKey(&ssKey[0], ssKey.size()); + Dbt datKey(ssKey.data(), ssKey.size()); // Exists int ret = pdb->exists(activeTxn, &datKey, 0); @@ -234,7 +234,7 @@ protected: Dbt datKey; unsigned int fFlags = DB_NEXT; if (setRange) { - datKey.set_data(&ssKey[0]); + datKey.set_data(ssKey.data()); datKey.set_size(ssKey.size()); fFlags = DB_SET_RANGE; }