aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bench/prevector.cpp26
-rw-r--r--src/prevector.h15
-rw-r--r--src/validation.h6
3 files changed, 43 insertions, 4 deletions
diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp
index 59c4af086e..2524e215e4 100644
--- a/src/bench/prevector.cpp
+++ b/src/bench/prevector.cpp
@@ -80,6 +80,30 @@ static void PrevectorDeserialize(benchmark::Bench& bench)
});
}
+template <typename T>
+static void PrevectorFillVectorDirect(benchmark::Bench& bench)
+{
+ bench.run([&] {
+ std::vector<prevector<28, T>> vec;
+ for (size_t i = 0; i < 260; ++i) {
+ vec.emplace_back();
+ }
+ });
+}
+
+
+template <typename T>
+static void PrevectorFillVectorIndirect(benchmark::Bench& bench)
+{
+ bench.run([&] {
+ std::vector<prevector<28, T>> vec;
+ for (size_t i = 0; i < 260; ++i) {
+ // force allocation
+ vec.emplace_back(29, T{});
+ }
+ });
+}
+
#define PREVECTOR_TEST(name) \
static void Prevector##name##Nontrivial(benchmark::Bench& bench) \
{ \
@@ -96,3 +120,5 @@ PREVECTOR_TEST(Clear)
PREVECTOR_TEST(Destructor)
PREVECTOR_TEST(Resize)
PREVECTOR_TEST(Deserialize)
+PREVECTOR_TEST(FillVectorDirect)
+PREVECTOR_TEST(FillVectorIndirect)
diff --git a/src/prevector.h b/src/prevector.h
index f36cfe4ff6..bcab1ff00c 100644
--- a/src/prevector.h
+++ b/src/prevector.h
@@ -264,8 +264,10 @@ public:
fill(item_ptr(0), other.begin(), other.end());
}
- prevector(prevector<N, T, Size, Diff>&& other) {
- swap(other);
+ prevector(prevector<N, T, Size, Diff>&& other) noexcept
+ : _union(std::move(other._union)), _size(other._size)
+ {
+ other._size = 0;
}
prevector& operator=(const prevector<N, T, Size, Diff>& other) {
@@ -276,8 +278,13 @@ public:
return *this;
}
- prevector& operator=(prevector<N, T, Size, Diff>&& other) {
- swap(other);
+ prevector& operator=(prevector<N, T, Size, Diff>&& other) noexcept {
+ if (!is_direct()) {
+ free(_union.indirect_contents.indirect);
+ }
+ _union = std::move(other._union);
+ _size = other._size;
+ other._size = 0;
return *this;
}
diff --git a/src/validation.h b/src/validation.h
index 7b215dea6b..8bc8842c54 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -43,6 +43,7 @@
#include <stdint.h>
#include <string>
#include <thread>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -330,6 +331,11 @@ public:
ScriptError GetScriptError() const { return error; }
};
+// CScriptCheck is used a lot in std::vector, make sure that's efficient
+static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
+static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
+static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
+
/** Initializes the script-execution cache */
[[nodiscard]] bool InitScriptExecutionCache(size_t max_size_bytes);