Skip to content

Commit

Permalink
Merge bitcoin#9349: Make CScript (and prevector) c++11 movable.
Browse files Browse the repository at this point in the history
2ddfcfd Make CScript (and prevector) c++11 movable. (Pieter Wuille)
  • Loading branch information
sipa committed Dec 27, 2016
2 parents 7aa7004 + 2ddfcfd commit 2db4cbc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/prevector.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ class prevector {
}
}

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;
Expand All @@ -263,6 +267,11 @@ class prevector {
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;
}
Expand Down
1 change: 0 additions & 1 deletion src/script/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ class CScript : public CScriptBase
}
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) { }
Expand Down
21 changes: 20 additions & 1 deletion src/test/prevector_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ class prevector_tester {
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
Expand Down Expand Up @@ -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();
}
}
}
}
Expand Down

0 comments on commit 2db4cbc

Please sign in to comment.