aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-03-14 10:42:17 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2017-03-14 10:43:10 +0100
commit67ed40ed82c61b03a8de93e91f6df1d6ff307105 (patch)
treec923db84242d772ab8b6e87c89ffa972dc1ef87b /src/prevector.h
parent1b046603b30ebfab6199a2f92015d507b248b590 (diff)
parent45a5aaf147ba65388333a8f40ae01b04a2d4a8c8 (diff)
downloadbitcoin-67ed40ed82c61b03a8de93e91f6df1d6ff307105.tar.xz
Merge #9505: Prevector Quick Destruct
45a5aaf Only call clear on prevector if it isn't trivially destructible and don't loop in clear (Jeremy Rubin) aaa02e7 Add prevector destructor benchmark (Jeremy Rubin) Tree-SHA512: 52bc8163b65b71310252f2d578349d0ddc364a6c23795c5e06e101f5449f04c96cbdca41c0cffb1974b984b8e33006471137d92b8dd4a81a98e922610a94132a
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 cba2e30057..177d81383e 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -11,6 +11,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
@@ -388,10 +389,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;
@@ -432,7 +437,9 @@ public:
}
~prevector() {
- clear();
+ if (!std::is_trivially_destructible<T>::value) {
+ clear();
+ }
if (!is_direct()) {
free(_union.indirect);
_union.indirect = NULL;