Skip to content

Commit 114b581

Browse files
committed
Prevector type
1 parent 4f09b77 commit 114b581

19 files changed

+874
-68
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ BITCOIN_CORE_H = \
125125
policy/fees.h \
126126
policy/policy.h \
127127
pow.h \
128+
prevector.h \
128129
primitives/block.h \
129130
primitives/transaction.h \
130131
protocol.h \

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ BITCOIN_TESTS =\
6464
test/pmt_tests.cpp \
6565
test/policyestimator_tests.cpp \
6666
test/pow_tests.cpp \
67+
test/prevector_tests.cpp \
6768
test/reverselock_tests.cpp \
6869
test/rpc_tests.cpp \
6970
test/sanity_tests.cpp \

src/core_memusage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "memusage.h"
1111

1212
static inline size_t RecursiveDynamicUsage(const CScript& script) {
13-
return memusage::DynamicUsage(*static_cast<const std::vector<unsigned char>*>(&script));
13+
return memusage::DynamicUsage(*static_cast<const CScriptBase*>(&script));
1414
}
1515

1616
static inline size_t RecursiveDynamicUsage(const COutPoint& out) {

src/hash.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "crypto/ripemd160.h"
1010
#include "crypto/sha256.h"
11+
#include "prevector.h"
1112
#include "serialize.h"
1213
#include "uint256.h"
1314
#include "version.h"
@@ -118,6 +119,13 @@ inline uint160 Hash160(const std::vector<unsigned char>& vch)
118119
return Hash160(vch.begin(), vch.end());
119120
}
120121

122+
/** Compute the 160-bit hash of a vector. */
123+
template<unsigned int N>
124+
inline uint160 Hash160(const prevector<N, unsigned char>& vch)
125+
{
126+
return Hash160(vch.begin(), vch.end());
127+
}
128+
121129
/** A writer stream (for serialization) that computes a 256-bit hash. */
122130
class CHashWriter
123131
{

src/memusage.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ template<typename X> static inline size_t DynamicUsage(const X * const &v) { ret
4646
static inline size_t MallocUsage(size_t alloc)
4747
{
4848
// Measured on libc6 2.19 on Linux.
49-
if (sizeof(void*) == 8) {
49+
if (alloc == 0) {
50+
return 0;
51+
} else if (sizeof(void*) == 8) {
5052
return ((alloc + 31) >> 4) << 4;
5153
} else if (sizeof(void*) == 4) {
5254
return ((alloc + 15) >> 3) << 3;
@@ -74,6 +76,12 @@ static inline size_t DynamicUsage(const std::vector<X>& v)
7476
return MallocUsage(v.capacity() * sizeof(X));
7577
}
7678

79+
template<unsigned int N, typename X, typename S, typename D>
80+
static inline size_t DynamicUsage(const prevector<N, X, S, D>& v)
81+
{
82+
return MallocUsage(v.allocated_memory());
83+
}
84+
7785
template<typename X, typename Y>
7886
static inline size_t DynamicUsage(const std::set<X, Y>& s)
7987
{

0 commit comments

Comments
 (0)