From 336d0e3be57ec4c5069fdc92caee4a6814a64a6b 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/4] streams: Add data() method to CDataStream Analogous to c++11 vector data(). (cherry picked from commit af4c44ce59aa643b3e03eaa121ec075f524227a5) --- src/streams.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/streams.h b/src/streams.h index 8680cde5b..4e0763f2b 100644 --- a/src/streams.h +++ b/src/streams.h @@ -177,6 +177,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 1fca92ae030a37335e6f1e4a06f4e344babf8262 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/4] 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. (cherry picked from commit a2141e415aed26bab756220d8707b5fb33e6fef8) --- src/streams.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/streams.h b/src/streams.h index 4e0763f2b..6407bcec0 100644 --- a/src/streams.h +++ b/src/streams.h @@ -106,12 +106,10 @@ public: Init(nTypeIn, nVersionIn); } -#if !defined(_MSC_VER) || _MSC_VER >= 1300 CBaseDataStream(const char* pbegin, const char* pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend) { Init(nTypeIn, nVersionIn); } -#endif CBaseDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end()) { @@ -194,7 +192,6 @@ public: vch.insert(it, first, last); } -#if !defined(_MSC_VER) || _MSC_VER >= 1300 void insert(iterator it, const char* first, const char* last) { if (last == first) return; @@ -208,7 +205,6 @@ public: else vch.insert(it, first, last); } -#endif iterator erase(iterator it) { From 06768aaed2e77db58d7f47f84dbdbbbd8351cb05 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/4] dbwrapper: Use new .data() method of CDataStream (cherry picked from commit adff950faeea95249df5f7536159701ea2202255) --- src/dbwrapper.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dbwrapper.h b/src/dbwrapper.h index e80baccab..5862f7f0a 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -57,12 +57,12 @@ 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; - leveldb::Slice slValue(&ssValue[0], ssValue.size()); + leveldb::Slice slValue(ssValue.data(), ssValue.size()); batch.Put(slKey, slValue); } @@ -73,7 +73,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); } @@ -103,7 +103,7 @@ public: CDataStream ssKey(SER_DISK, CLIENT_VERSION); ssKey.reserve(GetSerializeSize(ssKey, key)); ssKey << key; - leveldb::Slice slKey(&ssKey[0], ssKey.size()); + leveldb::Slice slKey(ssKey.data(), ssKey.size()); piter->Seek(slKey); } @@ -181,7 +181,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); @@ -214,7 +214,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 46bb82f816bbbffb7a07aa5de38934753a955814 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 15 Dec 2016 17:34:59 +0100 Subject: [PATCH 4/4] wallet: Use CDataStream.data() (cherry picked from commit 5113474a91b8dcac4de0e4566b9babd5da281f29) --- 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 088a74784..a374e751c 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -378,15 +378,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 1aa88f90b..76e315aa0 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -121,7 +121,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); @@ -233,7 +233,7 @@ protected: // Read at cursor Dbt datKey; if (fFlags == DB_SET || fFlags == DB_SET_RANGE || fFlags == DB_GET_BOTH || fFlags == DB_GET_BOTH_RANGE) { - datKey.set_data(&ssKey[0]); + datKey.set_data(ssKey.data()); datKey.set_size(ssKey.size()); } Dbt datValue;