mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Merge #9505: Prevector Quick Destruct
45a5aafOnly call clear on prevector if it isn't trivially destructible and don't loop in clear (Jeremy Rubin)aaa02e7Add prevector destructor benchmark (Jeremy Rubin) Tree-SHA512: 52bc8163b65b71310252f2d578349d0ddc364a6c23795c5e06e101f5449f04c96cbdca41c0cffb1974b984b8e33006471137d92b8dd4a81a98e922610a94132a
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user