Skip to content

Commit 2ddfcfd

Browse files
committed
Make CScript (and prevector) c++11 movable.
Such moves are used when reallocating vectors that contain them, for example.
1 parent e8cfe1e commit 2ddfcfd

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/prevector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ class prevector {
248248
}
249249
}
250250

251+
prevector(prevector<N, T, Size, Diff>&& other) : _size(0) {
252+
swap(other);
253+
}
254+
251255
prevector& operator=(const prevector<N, T, Size, Diff>& other) {
252256
if (&other == this) {
253257
return *this;
@@ -263,6 +267,11 @@ class prevector {
263267
return *this;
264268
}
265269

270+
prevector& operator=(prevector<N, T, Size, Diff>&& other) {
271+
swap(other);
272+
return *this;
273+
}
274+
266275
size_type size() const {
267276
return is_direct() ? _size : _size - N - 1;
268277
}

src/script/script.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ class CScript : public CScriptBase
394394
}
395395
public:
396396
CScript() { }
397-
CScript(const CScript& b) : CScriptBase(b.begin(), b.end()) { }
398397
CScript(const_iterator pbegin, const_iterator pend) : CScriptBase(pbegin, pend) { }
399398
CScript(std::vector<unsigned char>::const_iterator pbegin, std::vector<unsigned char>::const_iterator pend) : CScriptBase(pbegin, pend) { }
400399
CScript(const unsigned char* pbegin, const unsigned char* pend) : CScriptBase(pbegin, pend) { }

src/test/prevector_tests.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ class prevector_tester {
169169
pre_vector.swap(pre_vector_alt);
170170
test();
171171
}
172+
173+
void move() {
174+
real_vector = std::move(real_vector_alt);
175+
real_vector_alt.clear();
176+
pre_vector = std::move(pre_vector_alt);
177+
pre_vector_alt.clear();
178+
}
179+
180+
void copy() {
181+
real_vector = real_vector_alt;
182+
pre_vector = pre_vector_alt;
183+
}
184+
172185
~prevector_tester() {
173186
BOOST_CHECK_MESSAGE(passed, "insecure_rand_Rz: "
174187
<< rand_cache.Rz
@@ -240,9 +253,15 @@ BOOST_AUTO_TEST_CASE(PrevectorTestInt)
240253
if (((r >> 21) % 512) == 12) {
241254
test.assign(insecure_rand() % 32, insecure_rand());
242255
}
243-
if (((r >> 15) % 64) == 3) {
256+
if (((r >> 15) % 8) == 3) {
244257
test.swap();
245258
}
259+
if (((r >> 15) % 16) == 8) {
260+
test.copy();
261+
}
262+
if (((r >> 15) % 32) == 18) {
263+
test.move();
264+
}
246265
}
247266
}
248267
}

0 commit comments

Comments
 (0)