Skip to content

Commit

Permalink
Merge pull request #6914
Browse files Browse the repository at this point in the history
114b581 Prevector type (Pieter Wuille)
  • Loading branch information
laanwj committed Dec 1, 2015
2 parents 9490bd7 + 114b581 commit 327291a
Show file tree
Hide file tree
Showing 19 changed files with 874 additions and 68 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -124,6 +124,7 @@ BITCOIN_CORE_H = \
policy/fees.h \
policy/policy.h \
pow.h \
prevector.h \
primitives/block.h \
primitives/transaction.h \
protocol.h \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Expand Up @@ -65,6 +65,7 @@ BITCOIN_TESTS =\
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \
test/pow_tests.cpp \
test/prevector_tests.cpp \
test/reverselock_tests.cpp \
test/rpc_tests.cpp \
test/sanity_tests.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/core_memusage.h
Expand Up @@ -10,7 +10,7 @@
#include "memusage.h"

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

static inline size_t RecursiveDynamicUsage(const COutPoint& out) {
Expand Down
8 changes: 8 additions & 0 deletions src/hash.h
Expand Up @@ -8,6 +8,7 @@

#include "crypto/ripemd160.h"
#include "crypto/sha256.h"
#include "prevector.h"
#include "serialize.h"
#include "uint256.h"
#include "version.h"
Expand Down Expand Up @@ -118,6 +119,13 @@ inline uint160 Hash160(const std::vector<unsigned char>& vch)
return Hash160(vch.begin(), vch.end());
}

/** Compute the 160-bit hash of a vector. */
template<unsigned int N>
inline uint160 Hash160(const prevector<N, unsigned char>& vch)
{
return Hash160(vch.begin(), vch.end());
}

/** A writer stream (for serialization) that computes a 256-bit hash. */
class CHashWriter
{
Expand Down
10 changes: 9 additions & 1 deletion src/memusage.h
Expand Up @@ -46,7 +46,9 @@ template<typename X> static inline size_t DynamicUsage(const X * const &v) { ret
static inline size_t MallocUsage(size_t alloc)
{
// Measured on libc6 2.19 on Linux.
if (sizeof(void*) == 8) {
if (alloc == 0) {
return 0;
} else if (sizeof(void*) == 8) {
return ((alloc + 31) >> 4) << 4;
} else if (sizeof(void*) == 4) {
return ((alloc + 15) >> 3) << 3;
Expand Down Expand Up @@ -74,6 +76,12 @@ static inline size_t DynamicUsage(const std::vector<X>& v)
return MallocUsage(v.capacity() * sizeof(X));
}

template<unsigned int N, typename X, typename S, typename D>
static inline size_t DynamicUsage(const prevector<N, X, S, D>& v)
{
return MallocUsage(v.allocated_memory());
}

template<typename X, typename Y>
static inline size_t DynamicUsage(const std::set<X, Y>& s)
{
Expand Down

0 comments on commit 327291a

Please sign in to comment.