mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
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
This commit is contained in:
commit
67ed40ed82
@ -25,7 +25,8 @@ bench_bench_bitcoin_SOURCES = \
|
||||
bench/base58.cpp \
|
||||
bench/lockedpool.cpp \
|
||||
bench/perf.cpp \
|
||||
bench/perf.h
|
||||
bench/perf.h \
|
||||
bench/prevector_destructor.cpp
|
||||
|
||||
nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
|
||||
|
||||
|
36
src/bench/prevector_destructor.cpp
Normal file
36
src/bench/prevector_destructor.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2015-2017 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "bench.h"
|
||||
#include "prevector.h"
|
||||
|
||||
static void PrevectorDestructor(benchmark::State& state)
|
||||
{
|
||||
while (state.KeepRunning()) {
|
||||
for (auto x = 0; x < 1000; ++x) {
|
||||
prevector<28, unsigned char> t0;
|
||||
prevector<28, unsigned char> t1;
|
||||
t0.resize(28);
|
||||
t1.resize(29);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void PrevectorClear(benchmark::State& state)
|
||||
{
|
||||
|
||||
while (state.KeepRunning()) {
|
||||
for (auto x = 0; x < 1000; ++x) {
|
||||
prevector<28, unsigned char> t0;
|
||||
prevector<28, unsigned char> t1;
|
||||
t0.resize(28);
|
||||
t0.clear();
|
||||
t1.resize(29);
|
||||
t0.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(PrevectorDestructor);
|
||||
BENCHMARK(PrevectorClear);
|
@ -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,11 +389,15 @@ public:
|
||||
iterator erase(iterator first, iterator last) {
|
||||
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;
|
||||
}
|
||||
memmove(&(*first), &(*last), endp - ((char*)(&(*last))));
|
||||
return first;
|
||||
}
|
||||
@ -432,7 +437,9 @@ public:
|
||||
}
|
||||
|
||||
~prevector() {
|
||||
if (!std::is_trivially_destructible<T>::value) {
|
||||
clear();
|
||||
}
|
||||
if (!is_direct()) {
|
||||
free(_union.indirect);
|
||||
_union.indirect = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user