aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
diff options
context:
space:
mode:
authorJeremy Rubin <jeremy.l.rubin@gmail.com>2017-01-10 10:59:48 -0500
committerJeremy Rubin <jeremy.l.rubin@gmail.com>2017-01-10 18:23:10 -0500
commit45a5aaf147ba65388333a8f40ae01b04a2d4a8c8 (patch)
tree219a92c73d3b2e37f6af8c5885014424b6f34c68 /src/prevector.h
parentaaa02e7f24a2f7d1d390053e3b5007a304fd5f21 (diff)
downloadbitcoin-45a5aaf147ba65388333a8f40ae01b04a2d4a8c8.tar.xz
Only call clear on prevector if it isn't trivially destructible and don't loop in clear
Diffstat (limited to 'src/prevector.h')
-rw-r--r--src/prevector.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/prevector.h b/src/prevector.h
index 6b2f578f5c..9eb6f8c68f 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -10,6 +10,7 @@
#include <string.h>
#include <iterator>
+#include <type_traits>
#pragma pack(push, 1)
/** Implements a drop-in replacement for std::vector<T> which stores up to N
@@ -382,10 +383,14 @@ public:
iterator erase(iterator first, iterator last) {
iterator p = first;
char* endp = (char*)&(*end());
- while (p != last) {
- (*p).~T();
- _size--;
- ++p;
+ if (!std::is_trivially_destructible<T>::value) {
+ while (p != last) {
+ (*p).~T();
+ _size--;
+ ++p;
+ }
+ } else {
+ _size -= last - p;
}
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
return first;
@@ -426,7 +431,9 @@ public:
}
~prevector() {
- clear();
+ if (!std::is_trivially_destructible<T>::value) {
+ clear();
+ }
if (!is_direct()) {
free(_union.indirect);
_union.indirect = NULL;