File tree 3 files changed +49
-5
lines changed
3 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ bench_bench_dash_SOURCES = \
29
29
bench/lockedpool.cpp \
30
30
bench/perf.cpp \
31
31
bench/perf.h \
32
+ bench/prevector_destructor.cpp \
32
33
bench/string_cast.cpp
33
34
34
35
nodist_bench_bench_dash_SOURCES = $(GENERATED_TEST_FILES)
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2015-2017 The Bitcoin Core developers
2
+ // Distributed under the MIT software license, see the accompanying
3
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
+
5
+ #include " bench.h"
6
+ #include " prevector.h"
7
+
8
+ static void PrevectorDestructor (benchmark::State& state)
9
+ {
10
+ while (state.KeepRunning ()) {
11
+ for (auto x = 0 ; x < 1000 ; ++x) {
12
+ prevector<28 , unsigned char > t0;
13
+ prevector<28 , unsigned char > t1;
14
+ t0.resize (28 );
15
+ t1.resize (29 );
16
+ }
17
+ }
18
+ }
19
+
20
+ static void PrevectorClear (benchmark::State& state)
21
+ {
22
+
23
+ while (state.KeepRunning ()) {
24
+ for (auto x = 0 ; x < 1000 ; ++x) {
25
+ prevector<28 , unsigned char > t0;
26
+ prevector<28 , unsigned char > t1;
27
+ t0.resize (28 );
28
+ t0.clear ();
29
+ t1.resize (29 );
30
+ t0.clear ();
31
+ }
32
+ }
33
+ }
34
+
35
+ BENCHMARK (PrevectorDestructor);
36
+ BENCHMARK (PrevectorClear);
Original file line number Diff line number Diff line change 11
11
#include < string.h>
12
12
13
13
#include < iterator>
14
+ #include < type_traits>
14
15
15
16
#pragma pack(push, 1)
16
17
/* * Implements a drop-in replacement for std::vector<T> which stores up to N
@@ -388,10 +389,14 @@ class prevector {
388
389
iterator erase (iterator first, iterator last) {
389
390
iterator p = first;
390
391
char * endp = (char *)&(*end ());
391
- while (p != last) {
392
- (*p).~T ();
393
- _size--;
394
- ++p;
392
+ if (!std::is_trivially_destructible<T>::value) {
393
+ while (p != last) {
394
+ (*p).~T ();
395
+ _size--;
396
+ ++p;
397
+ }
398
+ } else {
399
+ _size -= last - p;
395
400
}
396
401
memmove (&(*first), &(*last), endp - ((char *)(&(*last))));
397
402
return first;
@@ -432,7 +437,9 @@ class prevector {
432
437
}
433
438
434
439
~prevector () {
435
- clear ();
440
+ if (!std::is_trivially_destructible<T>::value) {
441
+ clear ();
442
+ }
436
443
if (!is_direct ()) {
437
444
free (_union.indirect );
438
445
_union.indirect = NULL ;
You can’t perform that action at this time.
0 commit comments