Permalink
Browse files

Merge pull request #6914

114b581 Prevector type (Pieter Wuille)
  • Loading branch information...
laanwj committed Dec 1, 2015
2 parents 9490bd7 + 114b581 commit 327291af02d05e09188713d882bf68ac708c1077
View
@@ -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 \
@@ -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 \
View
@@ -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) {
View
@@ -8,6 +8,7 @@
#include "crypto/ripemd160.h"
#include "crypto/sha256.h"
+#include "prevector.h"
#include "serialize.h"
#include "uint256.h"
#include "version.h"
@@ -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
{
View
@@ -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;
@@ -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)
{
Oops, something went wrong.

0 comments on commit 327291a

Please sign in to comment.