From e241a63c23239adf54fe69baf02f3159222b71e4 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 5 Jun 2017 12:17:40 -0700 Subject: Clarify prevector::erase and avoid swap-to-clear --- src/prevector.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/prevector.h') 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::value) { -- cgit v1.2.3