Merge 5cce4d293e into merged_master (Bitcoin PR bitcoin/bitcoin#27334)

This commit is contained in:
Byron Hambly 2025-06-28 10:27:02 +02:00
commit 191bf91e0c
3 changed files with 43 additions and 4 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -44,6 +44,7 @@
#include <stdint.h>
#include <string>
#include <thread>
#include <type_traits>
#include <utility>
#include <vector>
@ -339,6 +340,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);