diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2017-11-07 14:24:30 -0800 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2018-03-07 07:04:07 -0800 |
commit | b3ea8ccb7af475703b97246a2baf2e105d24d6f9 (patch) | |
tree | 7d0f9685476bd35d332ebd7a43c0193bcb8c040d /src/key_io.cpp | |
parent | 3296a3bb7fc0a6c47b60c79e968dbf8175d6b716 (diff) |
Simplify Base32 and Base64 conversions
Diffstat (limited to 'src/key_io.cpp')
-rw-r--r-- | src/key_io.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/key_io.cpp b/src/key_io.cpp index 0cc4927679..c2dc511989 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -43,6 +43,7 @@ public: std::string operator()(const WitnessV0KeyHash& id) const { std::vector<unsigned char> data = {0}; + data.reserve(33); ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.begin(), id.end()); return bech32::Encode(m_params.Bech32HRP(), data); } @@ -50,6 +51,7 @@ public: std::string operator()(const WitnessV0ScriptHash& id) const { std::vector<unsigned char> data = {0}; + data.reserve(53); ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.begin(), id.end()); return bech32::Encode(m_params.Bech32HRP(), data); } @@ -60,6 +62,7 @@ public: return {}; } std::vector<unsigned char> data = {(unsigned char)id.version}; + data.reserve(1 + (id.length * 8 + 4) / 5); ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.program, id.program + id.length); return bech32::Encode(m_params.Bech32HRP(), data); } @@ -94,6 +97,7 @@ CTxDestination DecodeDestination(const std::string& str, const CChainParams& par // Bech32 decoding int version = bech.second[0]; // The first 5 bit symbol is the witness version (0-16) // The rest of the symbols are converted witness program bytes. + data.reserve(((bech.second.size() - 1) * 5) / 8); if (ConvertBits<5, 8, false>([&](unsigned char c) { data.push_back(c); }, bech.second.begin() + 1, bech.second.end())) { if (version == 0) { { |