aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-06-13 18:28:24 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-06-13 18:32:44 +0200
commita514ac3dcb6058f7567025e95805a4592323da82 (patch)
treeef759ee785a11f74d24ef6559bb93e04d1988ef3 /src
parent303c171b949be2c050f6f52e03b74ff1ad3dea63 (diff)
parente241a63c23239adf54fe69baf02f3159222b71e4 (diff)
downloadbitcoin-a514ac3dcb6058f7567025e95805a4592323da82.tar.xz
Merge #10534: Clarify prevector::erase and avoid swap-to-clear
e241a63 Clarify prevector::erase and avoid swap-to-clear (Pieter Wuille) Tree-SHA512: fa7602038feb4417158df13ee7c0351673acf38f8a824e75889710344c46a9b8d5f6059faeb521f73e48b7ad3e1a238a9e433e4b44f7c3b9085ff08ef65271fa
Diffstat (limited to 'src')
-rw-r--r--src/prevector.h6
-rw-r--r--src/script/script.h5
2 files changed, 9 insertions, 2 deletions
diff --git a/src/prevector.h b/src/prevector.h
index 177d81383e..dc17e7ce4b 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -387,6 +387,12 @@ public:
}
iterator erase(iterator first, iterator last) {
+ // Erase is not allowed to the change the object's capacity. That means
+ // that when starting with an indirectly allocated prevector with
+ // size and capacity > N, the result may be a still indirectly allocated
+ // prevector with size <= N and capacity > N. A shrink_to_fit() call is
+ // necessary to switch to the (more efficient) directly allocated
+ // representation (with capacity N and size <= N).
iterator p = first;
char* endp = (char*)&(*end());
if (!std::is_trivially_destructible<T>::value) {
diff --git a/src/script/script.h b/src/script/script.h
index 23706b9826..bbb37f049e 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -648,8 +648,9 @@ public:
void clear()
{
- // The default std::vector::clear() does not release memory.
- CScriptBase().swap(*this);
+ // The default prevector::clear() does not release memory
+ CScriptBase::clear();
+ shrink_to_fit();
}
};