compressor: use a prevector in compressed script serialization

Use a prevector for stack allocation instead of heap allocation during
script compression and decompression. These functions were doing
millions of unnecessary heap allocations during IBD.

We introduce a CompressedScript type alias for this prevector. It is
size 33 as that is the maximum size of a compressed script.

Fix the DecompressScript header to match the variable name from
compressor.cpp

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2020-05-01 17:31:38 -07:00
parent 844d2070a2
commit 83a425d25a
4 changed files with 27 additions and 13 deletions

View File

@@ -52,7 +52,7 @@ static bool IsToPubKey(const CScript& script, CPubKey &pubkey)
return false;
}
bool CompressScript(const CScript& script, std::vector<unsigned char> &out)
bool CompressScript(const CScript& script, CompressedScript& out)
{
CKeyID keyID;
if (IsToKeyID(script, keyID)) {
@@ -92,7 +92,7 @@ unsigned int GetSpecialScriptSize(unsigned int nSize)
return 0;
}
bool DecompressScript(CScript& script, unsigned int nSize, const std::vector<unsigned char> &in)
bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScript& in)
{
switch(nSize) {
case 0x00: