diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2016-12-13 19:36:46 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-12-21 18:28:33 -0800 |
commit | 2ddfcfd2d67bc2bd8aa4682ceaba6a59614e54d1 (patch) | |
tree | d2a24af811a5e43a5e3026a9ffed8a0aecb7fc7d /src | |
parent | e8cfe1ee2d01c493b758a67ad14707dca15792ea (diff) |
Make CScript (and prevector) c++11 movable.
Such moves are used when reallocating vectors that contain them,
for example.
Diffstat (limited to 'src')
-rw-r--r-- | src/prevector.h | 9 | ||||
-rw-r--r-- | src/script/script.h | 1 | ||||
-rw-r--r-- | src/test/prevector_tests.cpp | 21 |
3 files changed, 29 insertions, 2 deletions
diff --git a/src/prevector.h b/src/prevector.h index 25bce522dc..46af80d1e6 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -248,6 +248,10 @@ public: } } + prevector(prevector<N, T, Size, Diff>&& other) : _size(0) { + swap(other); + } + prevector& operator=(const prevector<N, T, Size, Diff>& other) { if (&other == this) { return *this; @@ -263,6 +267,11 @@ public: return *this; } + prevector& operator=(prevector<N, T, Size, Diff>&& other) { + swap(other); + return *this; + } + size_type size() const { return is_direct() ? _size : _size - N - 1; } diff --git a/src/script/script.h b/src/script/script.h index 76419c1495..a2b9d1b792 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -394,7 +394,6 @@ protected: } public: CScript() { } - CScript(const CScript& b) : CScriptBase(b.begin(), b.end()) { } CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { } CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { } CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { } diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index 1e5de2021c..1352ea722a 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -169,6 +169,19 @@ public: pre_vector.swap(pre_vector_alt); test(); } + + void move() { + real_vector = std::move(real_vector_alt); + real_vector_alt.clear(); + pre_vector = std::move(pre_vector_alt); + pre_vector_alt.clear(); + } + + void copy() { + real_vector = real_vector_alt; + pre_vector = pre_vector_alt; + } + ~prevector_tester() { BOOST_CHECK_MESSAGE(passed, "insecure_rand_Rz: " << rand_cache.Rz @@ -240,9 +253,15 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt) if (((r >> 21) % 512) == 12) { test.assign(insecure_rand() % 32, insecure_rand()); } - if (((r >> 15) % 64) == 3) { + if (((r >> 15) % 8) == 3) { test.swap(); } + if (((r >> 15) % 16) == 8) { + test.copy(); + } + if (((r >> 15) % 32) == 18) { + test.move(); + } } } } |