aboutsummaryrefslogtreecommitdiff
path: root/src/prevector.h
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-05-16 16:25:43 +0200
committerMacroFake <falke.marco@gmail.com>2022-05-16 16:25:47 +0200
commit07cb4dee5d12657e9cf33c442678e9a1cd2cec4a (patch)
tree9c72446e6cf79b00303efa418def85f82b8e1a48 /src/prevector.h
parent6b87fa540c407d167535561ac25e3225bf76d6cc (diff)
parent11e79084845a78e2421ea3abafe0de5a54ca2bde (diff)
downloadbitcoin-07cb4dee5d12657e9cf33c442678e9a1cd2cec4a.tar.xz
Merge bitcoin/bitcoin#24962: prevector: enforce is_trivially_copyable_v
11e79084845a78e2421ea3abafe0de5a54ca2bde prevector: only allow trivially copyable types (Martin Leitner-Ankerl) Pull request description: prevector uses `memmove` to move around data, that means it can only be used with types that are trivially copyable. That implies that the types are trivially destructible, thus the checks for `is_trivially_destructible` are not needed. ACKs for top commit: w0xlt: ACK https://github.com/bitcoin/bitcoin/pull/24962/commits/11e79084845a78e2421ea3abafe0de5a54ca2bde MarcoFalke: review ACK 11e79084845a78e2421ea3abafe0de5a54ca2bde 🏯 ajtowns: ACK 11e79084845a78e2421ea3abafe0de5a54ca2bde -- code review only Tree-SHA512: cbb4d8bfa095100677874b552d92c324c7d6354fcf7adab2ed52f57bd1793762871798b5288064ed1af2d2903a0ec9dbfec48d99955fc428f18cc28d6840dccc
Diffstat (limited to 'src/prevector.h')
-rw-r--r--src/prevector.h15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/prevector.h b/src/prevector.h
index 830b31e315..a52510930a 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -35,6 +35,8 @@
*/
template<unsigned int N, typename T, typename Size = uint32_t, typename Diff = int32_t>
class prevector {
+ static_assert(std::is_trivially_copyable_v<T>);
+
public:
typedef Size size_type;
typedef Diff difference_type;
@@ -411,15 +413,7 @@ public:
// representation (with capacity N and size <= N).
iterator p = first;
char* endp = (char*)&(*end());
- if (!std::is_trivially_destructible<T>::value) {
- while (p != last) {
- (*p).~T();
- _size--;
- ++p;
- }
- } else {
- _size -= last - p;
- }
+ _size -= last - p;
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
return first;
}
@@ -465,9 +459,6 @@ public:
}
~prevector() {
- if (!std::is_trivially_destructible<T>::value) {
- clear();
- }
if (!is_direct()) {
free(_union.indirect_contents.indirect);
_union.indirect_contents.indirect = nullptr;